Skip to content
Hill Liu edited this page Jun 15, 2021 · 29 revisions

Mocha

Mocha hook

JS-Dom global

JS-Dom custom url

import jsdom from "jsdom-global";
describe("Some Test", () => {
  let resetGlobal;
  before(() => {
    resetGlobal = jsdom(null, { url: "http://localhost" });
  });
  after(() => {
    resetGlobal();
  });
});

JS-Dom iframe

import jsdom from 'jsdom-global'
describe('Some Test', ()=>{
let reset;

  after(() => {
    jsdom();
  });

  beforeEach(
    () =>
      (reset = jsdom(null, {runScripts: 'dangerously', resources: 'usable'})),
  );

  afterEach(done => {
    reset();
  });

});

Iframe trigger onload event

  const el = document.createElement('div');
  document.body.appendChild(el);
  const uDom = mount(<Comp />, {attachTo: el});