Angularjs 有棱角的茉莉花2$q承诺不打电话。然后
我真的很惊讶,不知道发生了什么,也不知道解决办法是什么。。。我正在用这段代码进行测试<代码>。那么,永远不会调用:Angularjs 有棱角的茉莉花2$q承诺不打电话。然后,angularjs,jasmine,angular-promise,Angularjs,Jasmine,Angular Promise,我真的很惊讶,不知道发生了什么,也不知道解决办法是什么。。。我正在用这段代码进行测试。那么,永远不会调用: describe('PicturesSvc.updatePicturesList', function () { beforeEach(module('com.myapp')); it('download and update pictures list', function (done) { inject(function ($q, PicturesSv
describe('PicturesSvc.updatePicturesList', function () {
beforeEach(module('com.myapp'));
it('download and update pictures list', function (done) {
inject(function ($q, PicturesSvc, PicturesRemoteSvc) {
console.log($q);
var localPictures = [];
var remotePictures = [
{
id: 'A',
likes: 2,
},
];
$q(function (resolve, reject) {
console.log('going to resolve promise...');
resolve(remotePictures);
})
.then(function (val) {
console.log('Great! Promise has been resolved!', val);
done();
})
.catch(function (err) {
console.log('Something went wrong... :(', err);
done(err);
});
var deferred = $q.defer();
deferred.resolve('Test again!');
deferred.promise
.then(function (result) {
console.log(result);
});
});
});
输出如下所示:
LOG: function Q(resolver) { ... }
LOG: 'going to resolve promise...'
PicturesSvc.updatePicturesList
✖ download and update pictures list
Finished in 4.926 secs / 5.01 secs
SUMMARY:
✔ 0 tests completed
✖ 1 test failed
FAILED TESTS:
PicturesSvc.updatePicturesList
✖ download and update pictures list
PhantomJS 2.1.1 (Mac OS X 0.0.0)
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
为了
解决承诺,您还需要调用$scope.$apply()
更多信息:为了解决
承诺,您还需要调用$scope.$apply()
更多信息:尝试将整个构造函数交换为$q.resolve(remotePictures)。然后(…)
尝试将整个构造函数交换为$q.resolve(remotePictures)。然后(…)
由于它是一项服务,也可以使用$rootScope.$apply()
:)链接承诺有什么方法吗?现在我意识到承诺中的第二个。然后没有被调用(第一个。然后在服务中,所以在那里创建$rootScope.$apply()
)是没有意义的。因为它是一个服务,也可以使用$rootScope.$apply()
:)有没有办法链接承诺?现在我意识到承诺中的第二个。然后
没有被调用(第一个。然后
在服务中,所以在那里创建$rootScope.$apply()
)没有意义)。