簡體   English   中英

斷言當腳本加載事件觸發時布爾值已更改的單元測試

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM