在我的Angular/Typescript/Webpack項目中,我在代碼修改後重寫了單元測試。 「錯誤:意外的值‘未定義’被模塊DynamicTestModule「申報」錯誤:由模塊'DynamicTestModule'聲明的未定義值'undefined'
問題的症狀運行一個非常基本的組件測試時發生錯誤
爲了調試的問題,我清盤從組件的構造函數和基本上所有代碼中剝離出所有依賴項。該組件什麼都沒做,但我仍然有錯誤。它不可能是循環依賴,因爲沒有依賴關係。
文件的文件夾爲:
--profile
----profile.component.ts
----profile.component.spec.ts
----profile.component.html
----index.ts (barrel)
組件(以便找出問題刪除最有意義的代碼)是:
import { Component } from '@angular/core';
@Component({
selector: 'profile',
template: `<h1></h1>`
})
export class ProfileComponent {
title = 'Test Tour of Heroes';
constructor(){}
}
而且產品的規格有:
import { NO_ERRORS_SCHEMA, DebugElement } from '@angular/core';
import { ComponentFixture, TestBed }
from '@angular/core/testing';
import { ProfileComponent } from './profile.component';
console.log(ProfileComponent);
fdescribe('Component: Jasmine Spy Test',() => {
console.log(ProfileComponent);
let fixture: ComponentFixture<ProfileComponent>;
let component: ProfileComponent;
let fixture2: ComponentFixture<ProfileComponent>;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [ProfileComponent]
}).compileComponents();
fixture = TestBed.createComponent(ProfileComponent);
component = fixture.componentInstance;
});
it(`should create instance of objects`,() => {
expect(1).toBe(1);
});
});
版本:
"@angular/core": "^4.0.0",
"karma": "~1.4.1"
"webpack": "^2.3.3"
還有很多其他軟件包,但我不認爲這是問題。
我使用VisualCode 1.14.0(1.14.0)。
當我在類似的情況下遇到這個錯誤,它只是幫助退出所有正在運行的Node/npm skripts。 這聽起來像是一個Webpack bug ...但我無法重現它。 – jvoigt