【发布时间】:2017-12-21 19:33:20
【问题描述】:
运行 Jasmine 2.8。
我有一个测试案例,其中失败案例是在不应该触发的条件下触发的事件处理程序。请注意,此处提供事件的代码库是专有的内部开发系统的一部分,因此这些不是 DOM 事件,我没有利用任何流行的 JS 框架:
it('should trigger the event handler in state 0', function (done) {
function specCb(ev) {
expect(ev).toBeDefined();
expect(ev.data).toBe('some value');
done();
}
thing.state = 0;
simulateEventTrigger(thing, specCb);
});
it('should not trigger the event handler in state 1', function (done) {
function specCb(ev) {
done.fail('this should not be called in state 1');
}
thing.state = 1;
simulateEventTrigger(thing, specCb);
});
第二个规范总是会失败,因为要么调用了回调,这显式地使规范失败,要么规范超时等待done() 被调用,从而失败。如果 Jasmine 超时,如何让规范通过?
【问题讨论】:
标签: javascript jasmine jasmine2.0