Error: Please call "TestBed.compileComponents" before your test

Since you are already using webpack, theoretically you should not have to call the compileComponents() function according to the official doc here, because webpack inlines templates and css as part of the automated build process that precedes running the test.

One possible reason that your template/css are not inlined is the IDE(VisualStudio/WebStorm/IntelliJ) auto compiles your ts to js and the webpack loaders which target for js/ts files are trying to get applied on the already compiled js files instead of the source ts files.


Template fetching is asynchronous when your templates are not inlined into your components, so you need to tell Jasmine that. Change

beforeEach(() => {
    TestBed.configureTestingModule({ ... })
        .compileComponents();
    fixture = TestBed.createComponent(MessagesComponent);
    comp = fixture.componentInstance;
});

to

beforeEach(async(() => {
    TestBed.configureTestingModule({ ... })
        .compileComponents()
        .then(() => {
            fixture = TestBed.createComponent(MessagesComponent);
            comp = fixture.componentInstance;
        });
}));