Put in order · Angular course · Module 11: Testing

Order of creating a service mock

Arrange the steps of preparing a mocked service in beforeEach (top to bottom):

Items to put in order

  • await TestBed.configureTestingModule({ providers: [{ provide: SamuraiService, useValue: mockService }] }).compileComponents();
  • fixture = TestBed.createComponent(DojoComponent);
  • mockService = jasmine.createSpyObj('SamuraiService', ['getAll']);
  • mockService.getAll.and.returnValue(of([{ id: 1, name: 'Musashi' }]));

You can check the correct answer by solving this task in the CodeWorlds game.