Is there an equivalent method to loadFixtures method in jest. I can't seem to find anything in the jest docs. I'd like to be able to load a html fixture into jest test file ?
Or is there another way of doing html stub in jest that I'm missing ?
Note i'm not using React as its an old project with Jquery.
So instead of writing something like.
window.$ = require('jquery');
beforeEach(() => {
document.body.innerHTML =
'<div>' +
' <input id="exMonth" value="02" />' +
' <input id="exYear" value="2017" />'
'</div>';
});
test("exMonth should be 02", () =>{
expect($('#exMonth').val()).toBe('01');
});
I'd like to abstract my html out to a html fixture file and require it to the
document.body.innerHTML = require(myHtmlFixture.html)
You could use node's fs
for serverside tests.
var fs = require('fs');
var htmlFixture = fs.readFileSync('spec/fixtures/myFixture.html')
document.body.innerHTML = htmlFixture;
see: https://nodejs.dev/learn/reading-files-with-nodejs
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