Making assertions with mocha and chai when using react-testing-library?

Viewed 577

I would like to add react testing library to a project that uses mocha and chai for unit tests. I am bit stumped when I comes to writing assertions, most examples make use of jest and jest-dom. I am really keen to use assertions like toBeInTheDocument or toHaveTextContent

I am wondering if there is a chai plugin that is a suitable replacement for jest-dom? or what alternative solutions have you found for using react testing library with mocha and chai?

1 Answers

chai-dom is an alternative. It's a plugin that provides a subset of assertions on the dom. Unfortunately, the assertions are not as declarative or extensive as jest-dom.

Using chai-dom, we'd use exist in place of toBeInTheDocument and text in place of toHaveTextContent.

Related