-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(a11y): implemented a11y tree snapshot function
- Loading branch information
Showing
4 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { expect, fixture } from '@open-wc/testing'; | ||
import { a11ySnapshot } from '@web/test-runner-commands'; | ||
import type { TemplateResult } from 'lit'; | ||
import { html } from 'lit/static-html.js'; | ||
|
||
import { isChromium, isDebugEnvironment, isFirefox, isSafari } from '../dom'; | ||
|
||
import { waitForLitRender } from './wait-for-render'; | ||
|
||
/** | ||
* Get the a11y tree snapshot and tests its snapshot. | ||
* Since the snapshot is list of nodes, we have to stringify it | ||
* and create an html wrapper in order to use the `equalSnapshot` function. | ||
*/ | ||
async function a11yTreeEqualSnapshot(): Promise<void> { | ||
const snapshot = await a11ySnapshot({}); | ||
|
||
const htmlWrapper = await fixture(html`<p>${JSON.stringify(snapshot, null, 2)}</p>`); | ||
await expect(htmlWrapper).to.be.equalSnapshot(); | ||
} | ||
|
||
/** | ||
* The function creates and tests the accessibility tree snapshot on each browser. | ||
* If a template is passed, it will be instantiated before the snapshot is taken. | ||
* @param title The title of the section | ||
* @param template The optional html template | ||
*/ | ||
export function testA11yTreeSnapshot(title = 'A11y tree', template?: TemplateResult): void { | ||
describe(title, () => { | ||
beforeEach(async () => { | ||
if (template) { | ||
await fixture(template); | ||
} | ||
await waitForLitRender(document); | ||
}); | ||
|
||
(isChromium() && !isDebugEnvironment() ? it : it.skip)('Chrome', async () => { | ||
await a11yTreeEqualSnapshot(); | ||
}); | ||
|
||
(isSafari() && !isDebugEnvironment() ? it : it.skip)('Safari', async () => { | ||
await a11yTreeEqualSnapshot(); | ||
}); | ||
|
||
(isFirefox() && !isDebugEnvironment() ? it : it.skip)('Firefox', async () => { | ||
await a11yTreeEqualSnapshot(); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters