Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/thick-singers-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'pleasantest': minor
---

Add experimental accessibility snapshots feature
2 changes: 1 addition & 1 deletion babel.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = (api) => {
loose: true,
},
],
'@babel/preset-typescript',
['@babel/preset-typescript', { optimizeConstEnums: true }],
],
plugins: isRollup ? ['babel-plugin-un-cjs'] : [],
};
Expand Down
53 changes: 41 additions & 12 deletions examples/menu/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import type { PleasantestUtils } from 'pleasantest';
import { withBrowser, devices } from 'pleasantest';
import {
experimentalGetAccessibilityTree,
withBrowser,
devices,
} from 'pleasantest';

import { Liquid } from 'liquidjs';
import * as path from 'path';
const iPhone = devices['iPhone 11'];
Expand Down Expand Up @@ -75,23 +80,46 @@ test(
await expect(await screen.getByText(aboutText)).not.toBeVisible();

// Before JS initializes the menus should be links
let aboutBtn = await screen.getByRole('link', { name: /about/i });
await expect(aboutBtn).toHaveAttribute('href');
await expect(
await screen.queryByRole('button', { name: /about/i }),
).not.toBeInTheDocument();
expect(
await experimentalGetAccessibilityTree(
await screen.getByRole('navigation'),
),
).toMatchInlineSnapshot(`
navigation
heading "Company"
link "Company"
list
listitem
link "Products"
listitem
link "About"
listitem
link "Log In"
`);

await utils.runJS(`
import { init } from '.'
init()
`);

// The menus should be upgraded to buttons
aboutBtn = await screen.getByRole('button', { name: /about/i });
await expect(
await screen.queryByRole('link', { name: /about/i }),
).not.toBeInTheDocument();

// The menus should be upgraded to buttons,
const aboutBtn = await screen.getByRole('button', { name: /about/i });
expect(
await experimentalGetAccessibilityTree(
await screen.getByRole('navigation'),
),
).toMatchInlineSnapshot(`
navigation
heading "Company"
link "Company"
list
listitem
button "Products"
listitem
button "About"
listitem
link "Log In"
`);
// Login should still be a link, since it does not trigger a menu to open
const loginBtn = await screen.getByRole('link', { name: /log in/i });
await expect(loginBtn).toHaveAttribute('href');
Expand All @@ -110,6 +138,7 @@ test(
const productsBtn = await screen.getByRole('button', { name: /products/i });
// First click: opens about menu
await user.click(aboutBtn);

await expect(await screen.getByText(aboutText)).toBeVisible();
// Second click: closes about menu
await user.click(aboutBtn);
Expand Down
Loading