Intermittent test failures when upgrading from 3.3 to 3.4.16
See original GitHub issueI recently updated a project from version 3.3 to 3.4.16 and I’m now seeing intermittent errors in my tests. The tests are using React and @testing-library/react with jest. The main issue is that tests occasionally get stuck in the “Loading” state. In the documentation, https://www.apollographql.com/docs/react/development-testing/testing/#testing-the-success-state, states that all I should need to do is await a 0ms timeout, but that’s already being done. Is this a bug with @apollo/client or am I doing something wrong here?
An example of a test that is failing randomly.
test("renders control view when data exists", async () => {
await act(async () => {
renderControlViewForMockId(CONTROL_WITH_TESTS_AND_RELATED_CTRLS);
await new Promise((resolve) => setTimeout(resolve, 0));
});
const text = screen.getAllByText("Control 1");
expect(text.length).toBe(2);
expect(text[0]).toBeInTheDocument();
expect(text[1]).toBeInTheDocument();
});
The render method.
const renderControlViewForMockId = (id: string) => {
render(
<MockedProvider mocks={[...queryMocks, ...eventMocks]} addTypename={false}>
<MemoryRouter initialEntries={[`/testUrl/${id}`]}>
<Route path="/base/:baseId/sub/:subId">
<ModalProvider>
<ModalWrapper>
<ControlContainer />
</ModalWrapper>
</ModalProvider>
</Route>
</MemoryRouter>
</MockedProvider>
);
};
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:6 (3 by maintainers)
Top Results From Across the Web
How to Fix Flaky Tests - Semaphore CI
Step 1 – Commit to fixing the problem right away! ... A test that intermittently fails for no apparent reason — or works...
Read more >Release Notes - ZooKeeper - Version 3.4.14
ZOOKEEPER-3262 - Update dependencies flagged by OWASP report ... ZOOKEEPER-2712 - MiniKdc test case intermittently failing due to principal not found in ...
Read more >Introduction to Testing — Phoenix v1.6.15 - HexDocs
If we notice that a specific random seed triggers our intermittent failure, we can re-run the tests with that same seed to reliably...
Read more >Release Notes · CloudOps for AWS
3.4.16 ` ... SUP-408 Fixed commerce pipeline intermittent failures when ... CLOUD-1801 - Update AWS Lambda functions to use Node.js 12.
Read more >Release Notes for MongoDB 3.4
SERVER-37058 : Update with numeric field names inside an array can cause ... sync retry logic to be more resilient to intermittent failures...
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 all, I’ll close this issue for now since it appears to have been resolved in newer releases. Please let us know if you need more support here 🙏🏻
There is a
findAllByText()
method which seems to wrapgetAllBy()
call in an act so that it is awaitable (https://testing-library.com/docs/dom-testing-library/cheatsheet/#queries). I think that might help your use-case?I appreciate the concern, but I believe your issues are with React, not Apollo Client. We don’t consider the exact timings of the hooks to be part of the public interface, and APIs like
useEffect()
anduseState()
are not guaranteed to run synchronously, even if that’s how they work today. The hooks are being heavily refactored, and the timings will change between minor versions. The fact that react-testing-library has to implement all these polling methods is more or less an admission of this lack of precision on React’s part.I would try awaiting a
screen.findAllByText()
call and seeing if that helps with the flake!