Skip to content
This repository has been archived by the owner on May 2, 2023. It is now read-only.

Await an act in generateSnapshots to resolve warnings #17

Merged
merged 4 commits into from
Aug 13, 2021

Conversation

shlomnissan
Copy link
Contributor

@shlomnissan shlomnissan commented Aug 13, 2021

Overview

An Apollo update in Along resulted in new warnings:

Error: Warning: An update to UseQueryWrapper inside a test was not wrapped in act(...)

This is a known issue. Components that include Apollo's useQuery should await an act that pushes the test to the end of the event loop before they are tested. This change was also required in generateSnapshots so when components that use the useQuery hook are passed to it, they are rendered correctly before we're taking a snapshot.

Validation

I validated this fix manually by linking the library to the Along repo and running our test suite. I know that we're using generateSnapshots in traject as well, but it seems like it doesn't use Apollo so this should not have any impact (I haven't verified it because I don't have traject running locally).

References

https://trojanowski.dev/apollo-hooks-testing-without-act-warnings/
https://reactjs.org/docs/test-utils.html#act
enzymejs/enzyme#2073 (comment)
apollographql/apollo-client#5920

@shlomnissan shlomnissan force-pushed the sn/generate-snapshots branch from 2116acd to 73fb996 Compare August 13, 2021 12:28
@@ -0,0 +1,9 @@
import { act } from '@testing-library/react';

export default async function wait(ms = 0): Promise<void> {
Copy link
Contributor Author

@shlomnissan shlomnissan Aug 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is implemented in Along src/test/helpers.js. Once this patch is merged, we can import it from here instead.

Copy link
Contributor

@ahuth ahuth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ahuth ahuth merged commit 11407e8 into main Aug 13, 2021
@ahuth ahuth deleted the sn/generate-snapshots branch August 13, 2021 15:31
@ahuth
Copy link
Contributor

ahuth commented Aug 13, 2021

@shlomnissan
Copy link
Contributor Author

Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants