How do I unit test this login function, specifically the http post part? The http mock I made is not coded correctly to get into the \'if...else\' section of the code. I d
You can inject services into your test like
it('should do something',inject([YourService,XHRBackend],(service:YourService,mockBackend)=>{
mockBackend.connections.subscribe((connection)=>{
connection.mockRespond(new Response({body:JSON.stringify('your mock response')});
...
this will cause your post call to return with that mock data. What I am not certain of though is if you can actually inject XHRBackend without first doing a testbed and providing
{provide: XHRBackend, useClass: MockBackend}