How to use jest to test DOM element?

there is a function which adds an item or removes it from the class:
activeButtonClick export default function(button) {
 if (button.classList.contains('active')) {
button.classList.remove('active');
 } else {
button.classList.add('active');
}
}
module.exports = activeButtonClick;




How to write a test that would check that input DOMжлемента now have the class 'active'?

my sketch:
const activeBtn = require('./activeBtnClick');
const pencil = document.getElementById('pencil');

describe("activeBtnClick", () => {
 it("adds class to the button", () => {
??
});

});
April 4th 20 at 00:32
1 answer
April 4th 20 at 00:34
Solution
const activeBtn = require('./activeBtnClick');
const pencil = document.getElementById('pencil');

describe("activeBtnClick", () => {
 it("adds class to the button", () => {
except(button.classList.contains('active')).toEqual(true);
});
});

Find more questions by tags JavaScriptModular testing