Files
react-navigation/example/e2e/tests/Link.test.ts
Max Schmitt 016e7920df test: upgrade to the new Playwright test-runner (#9667)
Hey!

I made the following changes:

- Replaced Jest by the new Playwright test-runner
- Disabled the Jest linting rules for the Playwright e2e tests
- Rewrote the tests to the new test-runner
- Adjusted `Link.test.ts` which should be less flaky
- The tests run now across all three browsers: Chromium, Firefox, and WebKit

See here for reference about the new test-runner: https://playwright.dev/docs/test-intro

I extracted a fix for Netlify in #9668.

Let me know if you have any questions.
2021-06-13 17:38:46 +02:00

44 lines
1.3 KiB
TypeScript

import type { Page } from '@playwright/test';
import { expect, it } from './baseFixture';
it.beforeEach(async ({ page }) => {
await page.click('[data-testid=LinkComponent]');
});
const waitAndAssertPageHeading = async (
page: Page,
expectedHeading: string
) => {
await page.waitForSelector(`text=${expectedHeading}`);
const heading = (await page.accessibility.snapshot())?.children?.find(
(it) => it.role === 'heading'
)?.name;
expect(heading).toBe(expectedHeading);
};
it('loads the article page', async ({ page }) => {
await page.waitForURL('**/link-component/article/gandalf');
expect(await page.title()).toBe(
'Article by Gandalf - React Navigation Example'
);
await waitAndAssertPageHeading(page, 'Article by Gandalf');
});
it('goes to the album page and goes back', async ({ page }) => {
await page.click('[href="/link-component/music"]');
await page.waitForURL('**/link-component/music');
expect(await page.title()).toBe('Albums - React Navigation Example');
await waitAndAssertPageHeading(page, 'Albums');
await page.click('[aria-label="Article by Gandalf, back"]');
await page.waitForNavigation();
await page.waitForURL('**/link-component/article/gandalf');
expect(await page.title()).toBe(
'Article by Gandalf - React Navigation Example'
);
await waitAndAssertPageHeading(page, 'Article by Gandalf');
});