Skip to content

Commit 67a222f

Browse files
authored
Implement minimal accessibility snapshots (#236)
1 parent a8df962 commit 67a222f

19 files changed

Lines changed: 854 additions & 451 deletions

.changeset/thick-singers-roll.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'pleasantest': minor
3+
---
4+
5+
Add experimental accessibility snapshots feature

babel.config.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = (api) => {
1010
loose: true,
1111
},
1212
],
13-
'@babel/preset-typescript',
13+
['@babel/preset-typescript', { optimizeConstEnums: true }],
1414
],
1515
plugins: isRollup ? ['babel-plugin-un-cjs'] : [],
1616
};

examples/menu/index.test.ts

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import type { PleasantestUtils } from 'pleasantest';
2-
import { withBrowser, devices } from 'pleasantest';
2+
import {
3+
experimentalGetAccessibilityTree,
4+
withBrowser,
5+
devices,
6+
} from 'pleasantest';
7+
38
import { Liquid } from 'liquidjs';
49
import * as path from 'path';
510
const iPhone = devices['iPhone 11'];
@@ -75,23 +80,46 @@ test(
7580
await expect(await screen.getByText(aboutText)).not.toBeVisible();
7681

7782
// Before JS initializes the menus should be links
78-
let aboutBtn = await screen.getByRole('link', { name: /about/i });
79-
await expect(aboutBtn).toHaveAttribute('href');
80-
await expect(
81-
await screen.queryByRole('button', { name: /about/i }),
82-
).not.toBeInTheDocument();
83+
expect(
84+
await experimentalGetAccessibilityTree(
85+
await screen.getByRole('navigation'),
86+
),
87+
).toMatchInlineSnapshot(`
88+
navigation
89+
heading "Company"
90+
link "Company"
91+
list
92+
listitem
93+
link "Products"
94+
listitem
95+
link "About"
96+
listitem
97+
link "Log In"
98+
`);
8399

84100
await utils.runJS(`
85101
import { init } from '.'
86102
init()
87103
`);
88104

89-
// The menus should be upgraded to buttons
90-
aboutBtn = await screen.getByRole('button', { name: /about/i });
91-
await expect(
92-
await screen.queryByRole('link', { name: /about/i }),
93-
).not.toBeInTheDocument();
94-
105+
// The menus should be upgraded to buttons,
106+
const aboutBtn = await screen.getByRole('button', { name: /about/i });
107+
expect(
108+
await experimentalGetAccessibilityTree(
109+
await screen.getByRole('navigation'),
110+
),
111+
).toMatchInlineSnapshot(`
112+
navigation
113+
heading "Company"
114+
link "Company"
115+
list
116+
listitem
117+
button "Products"
118+
listitem
119+
button "About"
120+
listitem
121+
link "Log In"
122+
`);
95123
// Login should still be a link, since it does not trigger a menu to open
96124
const loginBtn = await screen.getByRole('link', { name: /log in/i });
97125
await expect(loginBtn).toHaveAttribute('href');
@@ -110,6 +138,7 @@ test(
110138
const productsBtn = await screen.getByRole('button', { name: /products/i });
111139
// First click: opens about menu
112140
await user.click(aboutBtn);
141+
113142
await expect(await screen.getByText(aboutText)).toBeVisible();
114143
// Second click: closes about menu
115144
await user.click(aboutBtn);

0 commit comments

Comments
 (0)