0
我正在测试一个服务功能,该功能会拨打众多$http.get()
调用。被测实际功能返回一个承诺。目前,该测试未通过response is undefined
。无法读取角度业务测试中未定义的属性
下面是测试:
it('should return the list of catalogues', inject(function ($q, bookService) {
var list;
var deferred = $q.defer();
var promise = deferred.promise;
promise.then(function (response) {
list = response.success; // Cannot read property 'success' of undefined
});
bookService.getCatalogues().then(function (response) {
deferred.resolve(response); // this line is hit first
});
$httpBackend.flush();
expect(list).toEqual(listOfBooks); // listOfBooks is defined outside test
}));
我在做什么错?
你确保响应对象包含一个成功的财产? –
这两个函数中的响应参数都为空。 –