我在运行ng test
时遇到了这个问题。它可以正常编译,并且ng build --prod
运行正常。我什至没有看到那些名称仅是Observables的变量,但是变量前面有一个$。
问题已更新
“ @ types /茉莉花”:“ 2.8.9”, “ @ types / jasminewd2”:“〜2.0.3”, “ @ types / node”:“〜8.9.4”, “ codelyzer”:“〜4.2.1”, “茉莉花芯”:“〜2.99.1”, “ jasmine-spec-reporter”:“〜4.2.1”, “ karma”:“〜1.7.1”, “ karma-chrome-launcher”:“〜2.2.0”, “业报-伊斯坦布尔报道”:“〜2.0.0”, “业力茉莉花”:“〜1.1.1”, “ karma-jasmine-html-reporter”:“ ^ 0.2.2”, “量角器”:“ ^ 5.4.2”, “ ts-node”:“〜5.0.1”, “ tslint”:“〜5.9.1”, “ typescript”:“〜2.7.2”
家长测试文件
describe('MembersComponent', () => {
let component: MembersComponent;
let fixture: ComponentFixture<MembersComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
ReactiveFormsModule,
HttpClientModule,
RouterTestingModule,
StoreModule.forRoot({})
],
declarations: [MembersComponent, ModalComponent],
providers: [{ provide: Store, useClass: StoreStub }]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(MembersComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
儿童测试文件
describe('ModalComponent', () => {
let component: ModalComponent;
let fixture: ComponentFixture<ModalComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ModalComponent],
imports: [FormsModule, ReactiveFormsModule, StoreModule.forRoot({})],
providers: [Store]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ModalComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
答案 0 :(得分:0)
如果您甚至不想测试store
,请尝试以下操作:
import { of } from 'rxjs';
class StoreStub{
select(){
return of<Team[]>([
{} // create dummy member objects
])
};
dispatch(){};
}
和spec
文件中的
TestBed.configureTestingModule({
imports: [
ReactiveFormsModule,
HttpClientModule,
RouterTestingModule,
StoreModule.forRoot({})
],
declarations: [MembersComponent, ModalComponent],
providers: [{ provide: Store, useClass: StoreStub}]
}).compileComponents();
}));