I'm trying to write unit tests for word-processor-like operations such as applying a list to a text node, but I found that document.execCommand
is not available to jsdom
, so I'm stumped as to how I could unit test the following operation:
document.getElementById('run').addEventListener('click', function() {
document.execCommand("insertorderedlist");
});
<div contenteditable="true">Foo</div>
<button id="run">Select "Foo" then Click</button>
I ended up having to mock the document.execCommand
explicitly:
// test-mocks.js
global.document.execCommand = function execCommandMock() { };
And then feeding my mocks into mocha directly:
"specs": "mocha --require @babel/register --require jsdom-global/register --require ignore-styles --require test-mocks.js ./path/to/tests.spec.js"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With