- Add router for each component
- Add UT for router
- Call real webapi instead of local data
- keep all test pass in todo.service.spec.ts
How to define jasmine spy
let httpClientSpy: { get: jasmine.Spy };
How to create jasmine spy
httpClientSpy = jasmine.createSpyObj('HttpClient', ['get']);
How to response response:
function asyncData<T>(data: T) {
return defer(() => Promise.resolve(data));
}
function asyncError<T>(errorObject: any) {
return defer(() => Promise.reject(errorObject));
}
const errorResponse = new HttpErrorResponse({
error: 'test 404 error',
status: 404, statusText: 'Not Found'
});
How to create HttpHeaders
import { HttpHeaders } from '@angular/common/http';
----
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json'
})
}