MockBackend没有被触发

时间:2018-08-28 10:55:38

标签: angular angular-testing

以下代码有什么问题?我正在尝试创建一个模拟后端,但没有被触发。

describe('createSession()', () => {
    it('Validate create session response',
                inject([Http, PayService, MockBackend], (http: Http, PayService: PayService, mockBackend: MockBackend) => {

                    mockBackend.connections.subscribe((c: MockConnection) => {
                        console.log("Coming inside......")
                        expect(c.request.url).toBe('https://test.com/v1/sessions');
                        c.mockRespond(new Response(new ResponseOptions({
                            body: 'This is a fake response'
                        })));
                    });
                    http.get("https://test.com").subscribe((res: Response) => {
                        console.log("inside");
                        expect(res.text()).toBe("This is a fake response");
                        expect(http.request).toHaveBeenCalledTimes(1);
                    })
                    console.log("end");
                }
                ));
});

0 个答案:

没有答案