【发布时间】:2016-03-05 05:30:38
【问题描述】:
if (isPromise(self.parentId)) {
console.log('DEBUG: outside then');
self.parentId.then(function (parent) {
console.log('DEBUG: inside then');
self.parentId = parent.id;
self.notes = Note.query({
parent_type: self.parentType,
parent_id: self.parentId,
});
});
我想测试当self.parentId 是promise 时Note.query 被调用。
it('when a promise is passed in', function () {
$controller('NotesController', {}, {
parentId: Lead.get({ id: 1 }).$promise,
parentType: 'leads',
});
expect(Note.query.called).to.equal(true);
});
这不起作用。外部日志发生,但内部日志没有。所以大概,问题在于承诺没有解决。
1) 为什么这不起作用? 2) 我怎样才能让它工作?
【问题讨论】:
标签: javascript angularjs unit-testing karma-runner