July 2017
Intermediate to advanced
384 pages
8h 23m
English
As you could see in the previous section, Angular comes with a testing library, @angular/core/testing, which offers the TestBed helper class and many other utilities. TestBed helps us to set up dependencies for tests--modules, components, providers, and so on. You can call TestBed.configureTestingModule() and pass the same metadata configuration object as used with @NgModule. The configureTestingModule() function should be called within a beforeEach() setup function.
Another useful function from the testing library is called inject(). It allows you to inject the specified objects into the tests. The following code snippet provides an example:
describe('MyService', () => { let service; beforeEach(() => TestBed.configureTestingModule({ ...Read now
Unlock full access