In theory, if you use a test runner that can be used in a browser (mocha and tape comes to mind), you could use a bundler to gather all your tests together and run them in a real browser. I did this experiment in 2018 with tape and dom-testing-library, at that time it worked great (just had to make sure to add { node: fs: 'empty' } on my webpack config).
If jest is the real problem then you could try one of these testing library wrapper
We already use Puppeteer for E2E testing, but currently transitioning to Playwright. Tried Cypress, which is awesome, but lacked the cross-domain support, which we still need for the time being. I have not familiarized myself with TestCafe tho.
But to sum up, you say we should bundle jest and all test files, open in a browser, and it should work with react-testing-library as long as it's bundled with it?
Do you reckon, from the top of your head, that it would be easy to support file watching as well?
But to sum up, you say we should bundle jest and all test files, open in a browser, and it should work with react-testing-library as long as it's bundled with it?
Oh no. Heavens no! That's not what I'm saying. Jest is a monster of a framework, I don't think you can make it run in a browser. I'm just trying to defend the testing-library family here.
Does it allow to run @testing-library/react based tests in Puppeteer?
No. pptr-testing-library was made to control puppeteer. So, technically puppeteer will render your app, then you use pptr-testing-library to query and manipulate the DOM (just like you would with react-testing-library).
In theory, if you use a test runner that can be used in a browser (mocha and tape comes to mind), you could use a bundler to gather all your tests together and run them in a real browser. I did this experiment in
2018
with tape and dom-testing-library, at that time it worked great (just had to make sure to add{ node: fs: 'empty' }
on my webpack config).If jest is the real problem then you could try one of these testing library wrapper
Thanks for your reply!
We already use
Puppeteer
for E2E testing, but currently transitioning toPlaywright
. TriedCypress
, which is awesome, but lacked the cross-domain support, which we still need for the time being. I have not familiarized myself withTestCafe
tho.But to sum up, you say we should bundle
jest
and all test files, open in a browser, and it should work withreact-testing-library
as long as it's bundled with it?Do you reckon, from the top of your head, that it would be easy to support file watching as well?
Oh no. Heavens no! That's not what I'm saying. Jest is a monster of a framework, I don't think you can make it run in a browser. I'm just trying to defend the
testing-library
family here.Do you use pptr-testing-library with puppeteer?
Nope, we created a test suite with
cucumber-js
and a lot of custom steps to support Gherkin for our PMs and non-technical staff.Does it allow to run
@testing-library/react
based tests inPuppeteer
?Because I'm under the impression, they won't work together like that, and that's where I may be wrong.
No. pptr-testing-library was made to control puppeteer. So, technically puppeteer will render your app, then you use
pptr-testing-library
to query and manipulate the DOM (just like you would withreact-testing-library
).Thanks! That's what I thought. What I would like ultimately, is my unit-tests to run in an actual browser.