单元测试以断言在脚本加载事件触发时布尔值已更改
Unit test to assert that a boolean has been changed when a scripts load event fires
我有一个加载 ckeditor.js
的脚本,加载后它会禁用自动内联..
var script = window.document.createElement('script');
script.setAttribute('type', 'text/javascript');
script.setAttribute('src', 'ckeditor.js');
window.document.body.appendChild(script);
script.addEventListener('load', function() {
CKEDITOR.disableAutoInline = true;
});
有什么方法可以 assert
在触发脚本的 load
事件处理程序后将 CKEDITOR.disableAutoInline
设置为 true
?
it('should ensure disableAutoInline is set to true when the ckeditor.js file is loaded in the browser', function() {
window.CKEDITOR = {
disableAutoInline: false
};
var ckeditorjs = window.document.querySelectorAll('[src=\'/ckeditor.js\']');
expect(ckeditorjs.length).to.equal(1);
});
需要在 script
..
上实际触发 load
事件
var ckeditorjs = window.document.querySelectorAll('[src=\'/ckeditor.js\']');
window.CKEDITOR = {
disableAutoInline: null
};
var event = new Event('load');
ckeditorjs[0].dispatchEvent(event);
expect(window.CKEDITOR.disableAutoInline).to.equal(true);
我有一个加载 ckeditor.js
的脚本,加载后它会禁用自动内联..
var script = window.document.createElement('script');
script.setAttribute('type', 'text/javascript');
script.setAttribute('src', 'ckeditor.js');
window.document.body.appendChild(script);
script.addEventListener('load', function() {
CKEDITOR.disableAutoInline = true;
});
有什么方法可以 assert
在触发脚本的 load
事件处理程序后将 CKEDITOR.disableAutoInline
设置为 true
?
it('should ensure disableAutoInline is set to true when the ckeditor.js file is loaded in the browser', function() {
window.CKEDITOR = {
disableAutoInline: false
};
var ckeditorjs = window.document.querySelectorAll('[src=\'/ckeditor.js\']');
expect(ckeditorjs.length).to.equal(1);
});
需要在 script
..
load
事件
var ckeditorjs = window.document.querySelectorAll('[src=\'/ckeditor.js\']');
window.CKEDITOR = {
disableAutoInline: null
};
var event = new Event('load');
ckeditorjs[0].dispatchEvent(event);
expect(window.CKEDITOR.disableAutoInline).to.equal(true);