I have a service I want to unit test in angular 4 typescript jasmine.
Now, the http
is doing a post
, and it returns an identity, however.. it is not sending anything.
I want to just have good code coverage but i don't understand how to quite complete this mocking statement.
here is the method for http post in my service file
addSession() {
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
return this.http.post(this.url, JSON.stringify({}), options)
.map((response: Response) => response.json());
}
Then the SPEC FILE , which i don't get what to really test, i suppose faking that i received a number back from the service http post, the response should be something like 000000014
Spec
import { TrackerFormService } from './tracker-form.service'
import { Observable } from 'rxjs/Observable'
describe('TrackerFormService', () => {
let trackerFormService: TrackerFormService,
mockHttp;
beforeEach(() => {
mockHttp = jasmine.createSpyObj('mockHttp', ['get', 'post', 'put']
)
trackerFormService = new TrackerFormService(mockHttp);
});
describe('addSession', () => {
it('add session ', () => {
// how to test, what to test?
// response , is a number? how to mock/fake this?
})
})
})