I have the following angular (4) test which should be testing a service, however, it seems to be passing before the Observable returns and expect
get's hit.
it('should enter the assertion', inject(
[ MockBackend, CellService ],
( backend: MockBackend, s: CellService ) => {
const urls = [];
backend.connections.subscribe((connection: MockConnection) => {
const req = connection.request;
urls.push(req.url);
if (req.method === RequestMethod.Get && req.url === '/api/getTest') {
connection.mockRespond(new Response(new ResponseOptions('enter mocked content')));
}
});
s.getCell('powders').subscribe(val => expect(true).toBeFalsy())
})
);
I tried adding async/await, but that didn't make a difference. How can I do this?
Update:
This code passes too ...
it('should enter the assertion', async(inject(
[ MockBackend, CellService ],
( backend: MockBackend, s: CellService ) => {
const urls = [];
backend.connections.subscribe((connection: MockConnection) => {
const req = connection.request;
urls.push(req.url);
if (req.method === RequestMethod.Get && req.url === '/api/getTest') {
connection.mockRespond(new Response(new ResponseOptions('enter mocked content')));
}
});
s.getCell('powders').subscribe(val => expect(true).toBeFalsy())
})
));