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({
providers: [MyService]
}));
beforeEach(inject([MyService], s => {
service = s;
}));
it('should return the city Bern', () => {
expect(service.getCities()).toContain('Bern')...