在我的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