Complete the code to inject the service in the test setup.
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.[1](MyService);
});Use TestBed.get() to retrieve the service instance for testing.
Complete the code to provide the service in the testing module.
beforeEach(() => {
TestBed.configureTestingModule({
providers: [[1]]
});
});Services must be listed in providers to be injectable in tests.
Fix the error in the test by completing the injection syntax.
it('should be created', inject([[1]], (service: MyService) => { expect(service).toBeTruthy(); }));
The inject function requires the service class to inject as the first argument.
Fill both blanks to create a spy object and provide it in the test module.
const spy = jasmine.createSpyObj('[1]', ['getData']); TestBed.configureTestingModule({ providers: [{ provide: [2], useValue: spy }] });
Create a spy object for the service name and provide it using provide with the service class.
Fill all three blanks to inject the service, spy on a method, and test the return value.
service = TestBed.[1](MyService); spyOn(service, '[2]').and.returnValue(of('mock data')); service.[3]().subscribe(data => { expect(data).toBe('mock data'); });
Use get to inject, spy on the getData method, and call it to test the mocked return.
