5 ms·
I don't unit-test ui components. Putting complex logic in ui components is a mistake anyway. Do test end to end.
by MrPatan 4y ago
I don't unit-test ui components. Putting complex logic in ui components is a mistake anyway. Do test end to end.
- JyB 4y ago> Do test end to end. What do you use concretely (and how) for this?
- rockwotj 4y agoCheckout https://playwright.dev https://playwright.dev
- sethammons 4y agoCheck out Cypress.io
- williamcotton 4y agoPuppeteer works very well. There is headless Chrome support in RSpec as well. Here’s an example using dependency injection and puppeteer: https://github.com/williamcotton/williamcotton.com/blob/master/test/app.test.js https://github.com/williamcotton/williamcotton.com/blob/mast...
- azangru 4y agoThere must be something better than loading the whole page, potentially with all sorts of database or network mockery required to provide it with all the data that it needs for rendering, in order to test how a particular button works. It's no coincidence that the release of Jest and Enzyme around 2015 produced such a huge enthusiasm in the frontend community.
- WorldMaker 4y agoThere's always the "Storybook approach" alternative: make sure all your UI components are individually renderable by pure props and then build standalone from your application story boards around those prop states. I tend to find that more useful for UI testing than unit tests because it gives designers something to critique and often better fits how they want to work. (Versus trying to assert things like specific DIVs exists, which might get rearranged or eliminated in the next design change.) It's easier to storyboard some complex component trees sometimes too.