I have a JavaScript library that I need to test but it is using document internally, how can I write unit tests for it?
What comes to mind is to use jsdom to simulate a document like
const assert = require("assert");
const JSDOM = require("jsdom").JSDOM;
const dom = new JSDOM(`<!DOCTYPE html>`);
global.document = dom.window.document;
describe(...
But this doesn't really look right to me? What is the proper way?
Aucun commentaire:
Enregistrer un commentaire