Mudanças entre as edições de "Unit testing with default Angular installation"
De Basef
| Linha 18: | Linha 18: | ||
</source> | </source> | ||
| + | |||
| + | == Asserting that some method is called with given arguments == | ||
| + | |||
| + | <source lang="javascript"> | ||
| + | |||
| + | let spySomeMethod = spyOn(someInstance, 'someMethod').and.callFake((arg1, arg2) => { | ||
| + | expect(arg1).toEqual(10); | ||
| + | expect(arg2).toEqual(20); | ||
| + | }); | ||
| + | |||
| + | // do something here | ||
| + | |||
| + | expect(spySomeMethod).toHaveBeenCalled(); | ||
| + | |||
| + | </source> | ||
| + | |||
Edição das 14h54min de 26 de abril de 2018
Getting instance of a service
let mockedLoginService = TestBed.get(LoginService);
Asserting that some method is called
let spySomeMethod = spyOn(someInstance, 'someMethod'); // do something here expect(spySomeMethod).toHaveBeenCalled();
Asserting that some method is called with given arguments
let spySomeMethod = spyOn(someInstance, 'someMethod').and.callFake((arg1, arg2) => { expect(arg1).toEqual(10); expect(arg2).toEqual(20); }); // do something here expect(spySomeMethod).toHaveBeenCalled();