Created
September 24, 2017 13:05
-
-
Save sourcerebels/d187b7899409173f34775a61805d1854 to your computer and use it in GitHub Desktop.
ts-mokito-sample.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { mock, instance, when, verify, anyString, anyOfClass } from 'ts-mockito'; | |
import { RequestOptions } from '@angular/http'; | |
import { HttpService } from '../common/http/http.service'; | |
import { LoginService } from './login.service'; | |
import { RouterTestingModule } from '@angular/router/testing'; | |
import { Observable } from 'rxjs'; | |
describe('login.service', () => { | |
let httpService : HttpService; | |
let loginService : LoginService; | |
beforeEach(() => { | |
console.log('beforeEach'); | |
httpService = mock(HttpService); | |
loginService = new LoginService(instance(httpService)); | |
}); | |
it('executes a POST request to the backend on user login', () => { | |
loginService.login('username', 'password'); | |
verify(httpService.executeRequest(anyString(), anyOfClass(RequestOptions))).called(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Una diferencia respecto a la versión de Java es que hay usar "instance" a la hora de proporcionar el mock al objeto que se está testeando.