【发布时间】:2015-06-30 21:36:37
【问题描述】:
我正在尝试测试将在 promise 的 .then 块中调用的间谍,但 then 块中的 done 似乎根本没有执行。
我收到timeout of 2000ms exceeded.
这是我正在测试的内容(异步):
/**
* Passed down to the LoginForm component to
* handle form submission.
*/
_submitHandler(data) {
return function(evt) {
evt.preventDefault && evt.preventDefault();
evt.stopPropagation && evt.stopPropagation();
return request('post', 'auth', data)
.then((res) => {
AuthActions.login();
return res;
})
}
}
这是我的测试:
describe('when it succeeds', () => {
it('should login', (done) => {
sinon.spy(AuthActions, 'login');
Instance._submitHandler({})({})
.then((res) => {
console.log('Called!!!');
expect(AuthActions.login.called).to.equal(true);
AuthActions.login.restore();
done();
}, done);
});
});
我正在使用 Karma 运行我的测试;柴和诗乃。
【问题讨论】:
-
你得到什么失败信息?
标签: javascript unit-testing promise mocha.js