const expectedHeroes = [{name: 'A'}, {name: 'B'}] const mockService ={getHeroes: () => expectedHeroes } it('should have heroes when HeroListComponent created', () => { // Pass the mock to the constructor as the Angular injector would const component = new HeroListComponent(mockService); expect(component.heroes.length).toEqual(expectedHeroes.length); });