【发布时间】:2015-10-01 04:02:24
【问题描述】:
如何测试 jasmine 中是否调度了 CustomEvent?当我尝试运行以下代码时,出现错误:“ReferenceError:找不到变量:CustomEvent”。
function testCustomEvent() {
window.dispatchEvent(new CustomEvent('myCustomEvent', {
detail: 'foo'
}));
}
describe('testCustomEvent', function() {
it('dispatches myCustomEvent', function() {
var eventSpy = jasmine.createSpy();
window.addEventListener('myCustomEvent', eventSpy);
testCustomEvent();
expect(eventSpy).toHaveBeenCalledWith('foo');
});
});
【问题讨论】:
标签: javascript unit-testing jasmine