mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-05-19 11:44:34 +08:00
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.
44 lines
1.3 KiB
TypeScript
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');
|
|
});
|