PouchDB ラッパーが注入された単体テストを試みているファクトリがあります。私が直面している問題は、モック PouchDB サービスが promise を返し、promise が解決されている間 (successCb を console.logout でき、正しいように見えます)、successCb 関数内のカルマの期待ステートメントが正しいコンソールであることです。ログ出力は、実行されていません。
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) {
});
}));
});