Testing?
See original GitHub issueWhat’s the best method for testing functions around Recoil? For example, if I had a function like this:
export const setAddComplete =
(addComplete: boolean, setNotesState: SetterOrUpdater<State>) => {
setNotesState(state => {
return {
...state,
addComplete,
};
});
};
How should I test it? I noticed the TestingUtils folder, but it looks like they aren’t included in the package.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:5 (1 by maintainers)
Top Results From Across the Web
COVID-19 Testing: What You Need to Know - CDC
Viral tests look for a current infection with SARS-CoV-2, the virus that causes COVID-19, by testing specimens from your nose or mouth. There...
Read more >Community-Based Testing Sites for COVID-19 - HHS.gov
Find Testing Resources in Your State. COVID-19 tests are available to everyone in the U.S., including the uninsured. Select your state below to...
Read more >Testing.com: Order Lab Tests and Blood Tests Online
Hundreds of easy-to-read lab testing guides. Confidential, secure and convenient online lab test ordering powered by trusted physician networks. Compassionate ...
Read more >Get free at-home COVID-19 tests this winter
15,000+ Free Testing Sites. No-cost antigen and PCR COVID-19 tests are available to everyone in the U.S., including the uninsured, at more than...
Read more >Find COVID-19 Tests
Find COVID-19 tests near you. Four ways to get tested: free community events or fixed test sites in NC, your medical provider or...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @adrianbw. Recoil requires React to run. You can test your Recoil Atoms and Selectors by creating a small React component that uses them and testing that in the way you would test any React component. https://reactjs.org/docs/testing.html
For example:
If you want to just test your state update function and not run Recoil then you could extract, export and test that code in isolation.
Before:
After:
For anyone who comes upon this and likes to write unit tests (a discussion I’m not going to get into), here’s a pattern I adopted, which uses
jest.fn()
to report out the atom’s value.Before adding
wrapper.unmount()
, I got in some loops with useEffect testing multiple functions (presumably because it was adding an instance on every mount?). There may be other ways to prevent this that I don’t know of.