本次测试:
it("getFooCount success", function () {
httpBackend.whenGET('/api/getFooCount').respond(1);
fooService.getFooCount();
httpBackend.flush();
expect(fooService.FooCount).toBe(1);
});
失败:“预期 null 为 1”(调用 api get 方法之前 fooService.fooCount 为 null)。
然而这个测试通过了:
it("getFooCount success", function () {
httpBackend.whenGET('/api/getFooCount').respond("1");
fooService.getFooCount();
httpBackend.flush();
expect(fooService.fooCount).toBe("1");
});
除了.respond()
.
我调用的 api 只返回一个整数,关于如何让它工作的任何建议,和/或它为什么失败?