-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Redux Toolkit Query #39
Conversation
Need to fix App.test.jsx. |
...which is mswjs/msw#1786, with some controversy in its comments... |
...is the controversial fix. |
So far have had to stop jsdom declaring that tests are running in a browser: mswjs/msw#1786 Fiddle with whatwg-fetch polyfill: reduxjs/redux-toolkit#1271 Still more things to fix, some presumably a consequence of first issue.
Now failing due to mswjs/msw#1796:
Didn't find a solution that worked in comments (e.g. https://mswjs.io/docs/migrations/1.x-to-2.x#requestresponsetextencoder-is-not-defined-jest). mswjs/msw#2015 is newer issue for same error message. I didn't see or try https://mswjs.io/docs/runbook#fixing-environment before moving to vitest:
|
The above merge from master brought change from jest to vitest. A lot more things work now. |
* App.test.tsx not passing yet... * Test utility functions are moved into new util.tsx file. * Table can't conditionally render if localAuthorityId is null any more since can't call hooks conditionally.
App.test.tsx is failing with Table still in loading... state:
The MSW event logging is:
The MSW handler seems correctly configured, since get error if add a typo to the http://example.com/api/fsa/localAuthority/:localAuthorityId URL:
...so it looks like test stops running before MSW can provide a response? Update: problem fixed by 25721c5 |
… written correctly. The exception silently stops the handler from handling the request, so findByRole() times out.
…ionselement-values-options not https://testing-library.com/docs/user-event/v13#clickelement-eventinit-options with <select>. Otherwise, user-event claims to click on non-first option, but event is always for first option.
…ep that don't need (added to try and debug test).
…() doesn't trigger polling and then makes something hang when clicking on another item.
…uk/terms-and-conditions, since there's now 15 minute caching by RTK Query. For robustness, the time is passed from the server to the front end via a new epochMillis property in Establishments.
Change from using fetch() in useEffect() for connecting to the API to using RTK Query.
The PR also changes from mocking the API via the app's FSA.tsx class to using Mock Service Worker library to mock it below RTK Query. I wasn't able to easily make MSW work with jest, so I replaced jest with vitest in #40.
RTK Query caches API results, so need to show time data was retrieved in the UI to comply with https://www.food.gov.uk/terms-and-conditions.
The API is now polled and the UI updated automatically.