Upon reviewing the test output, it appears that
console.log(dummyComponentInstance);
is being invoked and resulting in undefined
.
In addition, the log for console.log('beforeEach done');
is never displayed.
The code within dummy.component.spec.ts:
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { DummyComponent } from './dummy.component';
describe('DummyComponent', () => {
let dummyComponentInstance: DummyComponent;
let fixture: ComponentFixture<DummyComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [DummyComponent]
})
.compileComponents()
.then(() => {
fixture = TestBed.createComponent(DummyComponent);
dummyComponentInstance = fixture.componentInstance;
console.log('beforeEach done');
});
}));
it('should work', () => {
console.log(dummyComponentInstance);
expect(dummyComponentInstance instanceof DummyComponent).toBe(true, 'should create DummyComponent');
});
});
The content of dummy.component.ts:
import { Component } from '@angular/core';
@Component({
selector: 'dummy',
templateUrl: './dummy.component.html'
})
export class DummyComponent {
public initialized = false;
}
Error message after running the test:
07 06 2017 13:27:09.187:INFO [launcher]: Starting browser PhantomJS
07 06 2017 13:27:09.437:INFO [PhantomJS 2.1.1 (Linux 0.0.0)]: Connected on socket 4Vq49vX24cDAIZfjAAAA with id 34827962
LOG: undefined
PhantomJS 2.1.1 (Linux 0.0.0) DummyComponent should work FAILED
invokeTask@/tmp/karma-typescript-bundle-27168S216WqzJyZ6g.js:605:36
onInvokeTask@/tmp/karma-typescript-bundle-27168S216WqzJyZ6g.js:154:49
invokeTask@/tmp/karma-typescript-bundle-27168S216WqzJyZ6g.js:604:48
runTask@/tmp/karma-typescript-bundle-27168S216WqzJyZ6g.js:372:57
drainMicroTaskQueue@/tmp/karma-typescript-bundle-27168S216WqzJyZ6g.js:765:42
run@/tmp/karma-typescript-bundle-27168S216WqzJyZ6g.js:17951:29
/tmp/karma-typescript-bundle-27168S216WqzJyZ6g.js:17964:31
flush@/tmp/karma-typescript-bundle-27168S216WqzJyZ6g.js:17813:11
resolvePromise@/tmp/karma-typescript-bundle-27168S216WqzJyZ6g.js:951:78
resolvePromise@/tmp/karma-typescript-bundle-27168S216WqzJyZ6g.js:921:31
/tmp/karma-typescript-bundle-27168S216WqzJyZ6g.js:998:31
Expected false to be true, 'should create DummyComponent'.
src/app/dummy.component.spec.js:21:98