问题
I have a problem in testing in Angular 2.
describe('Spinner Component', () => {
beforeEach(() => TestBed.configureTestingModule({
declarations: [SpinnerComponent]
}).compileComponents());
beforeEach(() => {
fixture = TestBed.createComponent(SpinnerComponent);
comp = fixture.componentInstance;
fixture.detectChanges();
});
it('Should Create a Spinner Component', () => {
fixture.detectChanges();
var compiled = fixture.debugElement.nativeElement;
expect(compiled).toBeTruthy();
});
it('Should not be running', () => {
fixture.detectChanges();
expect(comp.isRunning).toBe(false);
});
});
The code above shows that the Spinner Component in the test 'Should not be running'. I do not know what causes this. I get an error in the console (Please see below). I have created the component instance on the second before each as seen in the code but it states that it is undefined when ran on the second test case. I need help. I would really appreciate it. Thanks in advance.
Error in console
来源:https://stackoverflow.com/questions/40039789/angular-2-testing-component-instance-is-undefined