Skip to content

Commit 66c7a7d

Browse files
committed
Fix flaky autoplay e2e test by awaiting animation settle
Replace immediate `expect(...).toBeNotVisible()` assertions with `waitFor(...).toBeNotVisible().withTimeout(500)` to handle the race condition where FlatList's paging scroll animation hasn't fully settled when the non-visibility check runs. Adjacent items can be briefly partially visible at the screen edge during the scroll animation, causing the immediate assertion to fail. https://claude.ai/code/session_01TSf7rodAUegEbivLi1hRY9
1 parent 2f2b2a5 commit 66c7a7d

1 file changed

Lines changed: 21 additions & 20 deletions

File tree

example/e2e/renderItems.e2e.test.js

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const SCREENS = {
99
};
1010

1111
const DELAY = 2 * 1000;
12+
const ANIMATION_SETTLE_TIMEOUT = 500;
1213

1314
describe('example with renderItems and data', () => {
1415
beforeAll(async () => {
@@ -31,54 +32,54 @@ describe('example with renderItems and data', () => {
3132
.toBeVisible()
3233
.withTimeout(DELAY);
3334

34-
await expect(element(by.id(SCREENS.one))).toBeNotVisible();
35-
await expect(element(by.id(SCREENS.two))).toBeNotVisible();
36-
await expect(element(by.id(SCREENS.three))).toBeNotVisible();
37-
await expect(element(by.id(SCREENS.fourth))).toBeNotVisible();
35+
await waitFor(element(by.id(SCREENS.one))).toBeNotVisible().withTimeout(ANIMATION_SETTLE_TIMEOUT);
36+
await waitFor(element(by.id(SCREENS.two))).toBeNotVisible().withTimeout(ANIMATION_SETTLE_TIMEOUT);
37+
await waitFor(element(by.id(SCREENS.three))).toBeNotVisible().withTimeout(ANIMATION_SETTLE_TIMEOUT);
38+
await waitFor(element(by.id(SCREENS.fourth))).toBeNotVisible().withTimeout(ANIMATION_SETTLE_TIMEOUT);
3839

3940
// after 2s => screen with one
4041
await new Promise((_) => setTimeout(_, DELAY / 2));
4142
await waitFor(element(by.id(SCREENS.one)))
4243
.toBeVisible()
4344
.withTimeout(DELAY);
4445

45-
await expect(element(by.id(SCREENS.zero))).toBeNotVisible();
46-
await expect(element(by.id(SCREENS.two))).toBeNotVisible();
47-
await expect(element(by.id(SCREENS.three))).toBeNotVisible();
48-
await expect(element(by.id(SCREENS.fourth))).toBeNotVisible();
46+
await waitFor(element(by.id(SCREENS.zero))).toBeNotVisible().withTimeout(ANIMATION_SETTLE_TIMEOUT);
47+
await waitFor(element(by.id(SCREENS.two))).toBeNotVisible().withTimeout(ANIMATION_SETTLE_TIMEOUT);
48+
await waitFor(element(by.id(SCREENS.three))).toBeNotVisible().withTimeout(ANIMATION_SETTLE_TIMEOUT);
49+
await waitFor(element(by.id(SCREENS.fourth))).toBeNotVisible().withTimeout(ANIMATION_SETTLE_TIMEOUT);
4950

5051
// after 4s => screen with two
5152
await new Promise((_) => setTimeout(_, DELAY / 2));
5253
await waitFor(element(by.id(SCREENS.two)))
5354
.toBeVisible()
5455
.withTimeout(DELAY);
5556

56-
await expect(element(by.id(SCREENS.zero))).toBeNotVisible();
57-
await expect(element(by.id(SCREENS.one))).toBeNotVisible();
58-
await expect(element(by.id(SCREENS.three))).toBeNotVisible();
59-
await expect(element(by.id(SCREENS.fourth))).toBeNotVisible();
57+
await waitFor(element(by.id(SCREENS.zero))).toBeNotVisible().withTimeout(ANIMATION_SETTLE_TIMEOUT);
58+
await waitFor(element(by.id(SCREENS.one))).toBeNotVisible().withTimeout(ANIMATION_SETTLE_TIMEOUT);
59+
await waitFor(element(by.id(SCREENS.three))).toBeNotVisible().withTimeout(ANIMATION_SETTLE_TIMEOUT);
60+
await waitFor(element(by.id(SCREENS.fourth))).toBeNotVisible().withTimeout(ANIMATION_SETTLE_TIMEOUT);
6061

6162
// after 6s => screen with three
6263
await new Promise((_) => setTimeout(_, DELAY / 2));
6364
await waitFor(element(by.id(SCREENS.three)))
6465
.toBeVisible()
6566
.withTimeout(DELAY);
6667

67-
await expect(element(by.id(SCREENS.zero))).toBeNotVisible();
68-
await expect(element(by.id(SCREENS.one))).toBeNotVisible();
69-
await expect(element(by.id(SCREENS.two))).toBeNotVisible();
70-
await expect(element(by.id(SCREENS.fourth))).toBeNotVisible();
68+
await waitFor(element(by.id(SCREENS.zero))).toBeNotVisible().withTimeout(ANIMATION_SETTLE_TIMEOUT);
69+
await waitFor(element(by.id(SCREENS.one))).toBeNotVisible().withTimeout(ANIMATION_SETTLE_TIMEOUT);
70+
await waitFor(element(by.id(SCREENS.two))).toBeNotVisible().withTimeout(ANIMATION_SETTLE_TIMEOUT);
71+
await waitFor(element(by.id(SCREENS.fourth))).toBeNotVisible().withTimeout(ANIMATION_SETTLE_TIMEOUT);
7172

7273
// after 8s => screen with fourth
7374
await new Promise((_) => setTimeout(_, DELAY / 2));
7475
await waitFor(element(by.id(SCREENS.fourth)))
7576
.toBeVisible()
7677
.withTimeout(DELAY);
7778

78-
await expect(element(by.id(SCREENS.zero))).toBeNotVisible();
79-
await expect(element(by.id(SCREENS.one))).toBeNotVisible();
80-
await expect(element(by.id(SCREENS.two))).toBeNotVisible();
81-
await expect(element(by.id(SCREENS.three))).toBeNotVisible();
79+
await waitFor(element(by.id(SCREENS.zero))).toBeNotVisible().withTimeout(ANIMATION_SETTLE_TIMEOUT);
80+
await waitFor(element(by.id(SCREENS.one))).toBeNotVisible().withTimeout(ANIMATION_SETTLE_TIMEOUT);
81+
await waitFor(element(by.id(SCREENS.two))).toBeNotVisible().withTimeout(ANIMATION_SETTLE_TIMEOUT);
82+
await waitFor(element(by.id(SCREENS.three))).toBeNotVisible().withTimeout(ANIMATION_SETTLE_TIMEOUT);
8283
});
8384

8485
// https://github.com/wix/Detox/blob/master/docs/APIRef.ActionsOnElement.md#swipedirection-speed-percentage

0 commit comments

Comments
 (0)