Browser support
rpearce opened this issue · comments
Given I have some code that creates a DOM Node like this
const button = () => {
const btn = document.createElement('button')
btn.addEventListener('click', e => { console.log(e) })
btn.innerHTML = 'CLICK ME PLZ'
return btn
}
what do I need to include with baretest
in order to have a browser environment and not receive DOM-related not-defined/reference errors when testing?
Would you recommend pulling in jsdom
or something? Are there any baretest
examples of working with the DOM?
Hey. Unfortunately Baretest is only supported on the server-side currently. Client-side support should be rather trivial to add and is now decided to be implemented later. Assertions should be handled by a third party lib — hope there is a good, simple solution for the client side.
@tipiirai I agree with that decision. Including jsdom
in jest
, for example, makes it work out of the box, but versioning and other things cans be issues. I get it!
Instead, what I'm asking about here is whether there are any examples you know of that use baretest
with a library like jsdom
to test the frontend?
I love baretest
's simplicity, and I want it to be my test runner, but before I dig too deep into getting jsdom
to work with it, I want to see if someone already has an example.
@rpearce you could use something like https://testing-library.com. I've used it successfully with Mocha, JSDom and vanilla JavaScript for https://plete.dev
@mroderick That testing for plete looks really clean! I've used testing-library with React but never with vanilla JS. Thank you for sharing, and when I circle back to trying this out, I'll consider following back up here.
Thanks guys!