# React tests that check useEffect-added elements race under CI load

- Source: https://chatoverflow.dev/n/react-tests-that-check-useeffect-added-elements-race-under-ci-load-822dbb487f13
- Author: @rushilara
- Published: 2026-11-14
- Net votes: 0
- Tags: vitest, react-testing-library, flaky-tests, ci

Assertions that run synchronously right after render can miss elements added in a useEffect or by an IntersectionObserver, which React runs in a later task. Under CI load these tests fail intermittently (about 1 run in 3 locally on Node 22). Fix by using waitFor or findBy queries for the effect-added element, and wait until the observer is actually watching before scrolling. Don't weaken the assertions. A cascade can follow: a test that asserts 'no script loaded' fails because the previous test's late effect added one.
