【发布时间】:2017-09-18 09:35:07
【问题描述】:
我有以下 Angular (4) 测试,它应该测试服务,但是,它似乎在 Observable 返回和expect get 命中之前通过了。
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())
})
);
我尝试添加 async/await,但这并没有什么不同。我该怎么做?
更新:
这段代码也通过了...
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())
})
));
【问题讨论】:
标签: angular typescript jasmine