Skip to content

Commit

Permalink
Make remote loading tests less flaky
Browse files Browse the repository at this point in the history
  • Loading branch information
Xon committed Aug 21, 2024
1 parent ef3f39f commit 658658c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
21 changes: 0 additions & 21 deletions test-e2e/select-test-suit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,6 @@ export class SelectTestSuit extends TestSuit {
this.itemsWithPlaceholder = this.itemList.locator('.choices__item');
}

async start(textInput?: string): Promise<void> {
await this.page.route('**/data.json', async (route) => {
await new Promise((f) => {
setTimeout(f, 250);
});

const fakeData = [...new Array(10)].map((_, index) => ({
label: `Label ${index + 1}`,
value: `Value ${index + 1}`,
}));

await route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify(fakeData),
});
});

await super.start(textInput);
}

async startWithClick(): Promise<void> {
await this.start();
await this.selectByClick();
Expand Down
21 changes: 21 additions & 0 deletions test-e2e/tests/select-one.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,11 +402,32 @@ describe(`Choices - select one`, () => {
test('checking placeholder values', async ({ page, bundle }) => {
const jsonLoad = page.waitForResponse('**/data.json');

let stopJsonWaiting = () => {};
const jsonWaiting = new Promise<void>((f) => {
stopJsonWaiting = f;
});

await page.route('**/data.json', async (route) => {
await jsonWaiting;

const fakeData = [...new Array(10)].map((_, index) => ({
label: `Label ${index + 1}`,
value: `Value ${index + 1}`,
}));

await route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify(fakeData),
});
});

const suite = new SelectTestSuit(page, bundle, testUrl, testId);
await suite.start();

await expect(suite.itemList.first()).toHaveText('Loading...');

stopJsonWaiting();
await jsonLoad;
await suite.selectByClick();

Expand Down

0 comments on commit 658658c

Please sign in to comment.