我有一个工厂,我正在尝试使用注入的 PouchDB 包装器对其进行单元测试。我遇到的问题是我有模拟 PouchDB 服务返回一个承诺,而当承诺解决时(我可以 console.log 退出successCb,它看起来是正确的),成功Cb 函数中的业力期望语句在正确的控制台中。日志输出是,没有运行。
我不确定为什么console.log 输出工作正常但expect 语句不执行,任何有关此事的帮助将不胜感激!
以下是相关的代码片段:
[单元测试设置]
var mockCalendarsResource, mockPouchDB;
var mockPouchDB = function(name) {
this.name = name;
this.post = function(newCalendar, successCb, errorCb) {
var promise = new Promise(function(successCb, errorCb) {
newCalendar._id = 2;
successCb(newCalendar);
});
return promise;
};
}
beforeEach(function() {
module(function($provide) {
$provide.value('Pouch', mockPouchDB);
});
angular.mock.inject(function($injector) {
mockCalendarsResource = $injector.get('Calendar');
});
});
[业力单元测试代码]
describe('The calendar resource function create', function() {
it('should create a new calendar', inject(function(Calendar) {
var result = mockCalendarsResource.create({
name: "Testing"
},
function(response) {
//console.log here works correctly //
//These are the expect statements not functioning //
expect(response._id).toBe(2);
expect(response.name).toBe('Testing');
// Could put any expectation here and it will pass or not be checked //
}, function(err) {
});
}));
});