[英]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;
});
一旦觸發腳本的load
事件處理程序,是否有辦法assert
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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.