Testing

In any sizeable application, having a base of tests to guarantee the function of your application is crucial. Considering we have automated this entire process, we don’t want any flakiness or unstable tests as a result of an upgrade or migration, so making sure all our tests operated as normal was the next priority after the application compiled and booted.

As it turns out, the “older” way of unit testing was outdated and no longer functioned. In its original form, it looked a bit like this:

const testBed = getTestBed() testBed.configureTestingModule({

imports: [HttpClientTestingModule, MatIconModule]

})

testBed.initTestEnvironment(

BrowserDynamicTestingModule,

platformBrowserDynamicTesting(),

)

The TestBed has seen a complete overhaul, and is no longer supposed to be instantiated before use. More importantly, the TestBed needs to be initialized before any configureTestingModule({}) can be called. The errors we got for this were a little cryptic, but our solution looks like this:

TestBed.initTestEnvironment(

BrowserDynamicTestingModule,

platformBrowserDynamicTesting(),

)

TestBed.configureTestingModule({

imports: [HttpClientTestingModule, MatIconModule]

})

Then there was the issue of TestBed.get(SYMBOL_TO_INJECT) being deprecated in favor of the more strongly typed TestBed.inject<T> . Unfortunately at the time of writing, there was no automated migration path for this. This meant a manual find & replace of TestBed.get with TestBed.inject<any> and then going over all replaced cases to add the proper expected type.

This took maybe 30 minutes and turned out to be a simple issue to solve.

This was the end of my compile issues and the tests started running and functioning again. Of course, some tests failed because of the stricter compilation of HTML templates, so the unit tests pointed out a few flaws in our application. The stricter checking of templates, in my opinion, is a very good thing!

For E2E testing we use Testcafé, which just ran as we had left it. Of course, the application needs to compile and start before it does.