dom-testing-library
to test any JS framework
dom-testing-library
with React
dom-testing-library
with Preact
dom-testing-library
with jQuery
dom-testing-library
with Dojo
dom-testing-library
with HyperApp
dom-testing-library
with AngularJs
dom-testing-library
with Angular
dom-testing-library
with Vue
dom-testing-library
with Mithril
dom-testing-library
with Svelte
dom-testing-library
with from-html
render
function to abstract the
repetitive work of rendering the
component you will be
testing
dom-testing-library
to get all the different
functions for getting and
querying elements in your
container using getQueriesForElement
render
function
render
function async, and await
when calling your render
function
await
to wait for the update before
asserting. Most async updates
occur at the end of the current
event loop, but not all. If you
know updates happen via the
event loop, you can simply use await
and dom-testing-library
s wait
. If they are
non-deterministically updated,
e.g. not using the event loop,
you'll need to assert
inside wait
s callback so that Jest keeps
asserting until either the UI is
updated or the test fails.
dom-testing-library
with React
react.test.js
render
function that will mount our
component
document.createElement
.
ReactDOM.render
we render components into that
container
body
to append all event handlers. We
need to account for that, so we
append our container to body
using document.body.appendChild
getQueriesForElement
from dom-testing-library
to get all the different
queries, and return them in our
own render
function
cleanup
function in render that first
unmounts our component using ReactDOM.unmountComponentAtNode
which accepts the container we
mounted our component at. We
also use document.body.removeChild
to remove our component from the
DOM. cleanup
will need to be used after every
test to ensure that subsequent
tests do not contain previously
rendered components.
dom-testing-library
with Preact
preact.test.js
render
function
document.createElement('div')
Preact.render(ui,
container)
to render our component on that
container
container
to dom-testing-library
s getQueriesForElement
function, spreading it
setTimeout
with a delay of 0
async await
with dom-testing-library
s wait
function to wait for the next
tick of the event loop before
asserting
async await
is cleaner, and we can clean things up
further by extending dom-testing-library
s fireEvent
by making every method async
:
fire-event-async.js
dom-testing-library
with jQuery
jquery
components we use getQueriesForElement
on a section of DOM that we can create
using jQuery.
dom-testing-library
with Dojo
dom-testing-library
with HyperApp
render
function async, and await
the result of rendering before making
any assertions or queries.
dom-testing-library
with AngularJs
dom-testing-library
with Angular
dom-testing-library
with Vue
async / await
when asserting on events that result in
state being updated.
dom-testing-library
with Mithril
dom-testing-library
s wait
function. This will continuously call
the assertion within a 4000ms window
until the assertion passes, otherwise
failing the test.
dom-testing-library
with Svelte
async / await
for state updates.
dom-testing-library
with from-html
from-html
leaves it up to the user to manage state
etc. Events are handled synchronously,
so there's no need for async / await
.