-
Notifications
You must be signed in to change notification settings - Fork 0
chore(test): introduce some tests related to projects hooks #52
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
base: main
Are you sure you want to change the base?
Conversation
867cbd4 to
3c382cc
Compare
3c382cc to
3e8afbb
Compare
3e8afbb to
3165747
Compare
| ) | ||
|
|
||
| // Since useSingleProject() is Suspense-based, we need to simulate waiting for the data to initially resolve | ||
| await waitFor(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on react-hooks-testing-library tests I'm not sure this is how to test a suspense hook. The docs aren't great on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah me neither. was mostly drawing inspiration from how React Query does its suspense hook tests: https://github.com/TanStack/query/blob/main/packages/react-query/src/__tests__/useSuspenseQuery.test.tsx
major difference is the DOM oriented approach as opposed to purely hook-based, which may be an important distinction
|
Took a quick look at this, but did not go too deep into the details. I left a comment questioning how to wait for suspense hooks - the docs are not clear at all. This does smell of a race condition. One way to force a delay easily to expose any issues would be to over-ride the const { port1, port2 } = new MessageChannel()
slowdown(port1)
slowdown(port2)
function slowdown(port) {
const postMessageOrig = port.postMessage.bind(port)
port.postMessage = (message) => {
setTimeout(() => postMessageOrig(message), 200)
}
}That should ensure that everything is actually asynchronous, and ensure a loading state. Haven't tested it though, just an idea. |
|
FYI I ran tests with the slowdown from above and got the same failing tests as seen in CI: Either the code has a bug, or the tests aren't quite right. |
Yeah I suspect this too. I am curious about whether the Node version might be related. |
Non-exhaustive first attempt to introduce some more e2e-like tests for hooks related to projects. The approach is more data-oriented as opposed to the recommended approach of being DOM-oriented, mostly becaues it felt easier to focus on the tests I was interested in. I could imagine that we'd want to add tests that also work with a DOM to test out how the hooks interact with things like suspense and error boundaries, but think that can be a follow-up if desired.
Would've liked the tests to have more assertions to guarantee the lifecycle of hooks (e.g. checking pending status for writes or isRefetching for reads), but I'm pretty sure I'm running into the issue highlighted in TanStack/query#4379. There isn't an easy way to inject an artificial delay for every mutation and query function that interfaces with core, which I can confirm solves the issue, but open to ideas on alternative approaches (maybe setting up a worker that has some ipc overhead??).