【发布时间】:2016-04-01 15:55:41
【问题描述】:
我有一个函数,当事情发生时使用通知来更新 UI:
promiseFunction.poll().then(
function resolve() {},
function reject() {},
function notify() {
console.log('Notify was called');
}
);
还有一个单元测试试图模拟通知
it('will call notify', function () {
sinon.stub(promiseFunction, 'poll', function () {
var pollDeferred = $q.defer();
pollDeferred.notify();
return pollDeferred.promise;
});
systemUnderTest.run();
$rootScope.$digest();
});
日志“通知被调用”永远不会被记录。为什么通知功能不会触发?
【问题讨论】:
-
如果你改为调用 $rootScope.$apply() 会发生什么?
-
同样的事情发生了。我现在实际上已经解决了,将添加答案
标签: javascript angularjs promise mocha.js notify