![](/img/trans.png)
[英]Cannot read property 'injector' of null jasmine angular 2
[英]angular 4 unit test: Cannot read property 'injector' of null
我必須進行以下測試(使用業力和茉莉花),請注意我在其他地方調用了initTestEnvironment
,但是我驗證了它是否被調用(使用console.log)。
每當我運行它時,我都會得到: TypeError: Cannot read property 'injector' of null
如您所見, MyService
只是一個空類,以證明上述錯誤發生在我嘗試注入的每個服務中。
@Injectable()
export class MyService {
}
describe('some tests', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
HttpModule,
HttpClientModule
],
providers: [
MyService
]
});
});
it('just a test', () => {
TestBed.get(MyService); // this causes the error
expect(true).toBeTruthy();
});
});
任何想法可能導致此問題,以及如何解決?
我看不到我的問題,尤其是那里的許多教程都以完全相同的方式來做。
好吧,至少在yurzuis評論后,這是恐懼和期望的:測試本身一切都很好。
但是我有一個帶范圍內軟件包的mono repo,測試是從主項目運行的(而不是范圍內軟件包本身),不幸的是,角度軟件包之間存在版本不匹配,從而導致了這些問題。
因此,我必須改進測試設置,以防止將來出現此問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.