Cannot read property 'injector' of null jasmine angular 2

元气小坏坏 提交于 2019-12-05 06:41:18

At some point (prior to any tests being executed) you need to initial the testing environment, by calling TestBed.initTestEnvironment(...).

You would normally see this done in a karma-test-shim file, as seen in the angular quickstart (same quickstart from testing docs). But if you're not using this technique, then you need to do this in your test files. But the initTestEnvironment should only be called once, so you need to also reset it in each test file

import { BrowserDynamicTestingModule,
         platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';

beforeAll(() => {
  TestBed.resetTestEnvironment();
  TestBed.initTestEnvironment(BrowserDynamicTestingModule,
                              platformBrowserDynamicTesting());
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!