Comment

Comment by JMTQp8lwXL

> If you have any asynchronous things going on in `useEffect`, you'll have to do something similar to that `await(0)` song and dance in tests. This specifically affects tests if you do things like update the UI by toggling loading spinners on await.

You should have a core (pure) functional component, that doesn't perform network requests, and an outer component for side effects.

Your testing for the inner component becomes trivial: Do the correct props product the correct HTML? Fairly trivial to validate. Use Enzyme, react-testing-library, etc.

The outer component, which contains side effects, can be covered through an end-to-end testing tool like Cypress.

parent JMTQp8lwXL 5 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton