Skip to content

Commit

Permalink
docs: add mixed VSR and Jest test example
Browse files Browse the repository at this point in the history
  • Loading branch information
jlp-craigmorten committed Jun 24, 2024
1 parent 20309e8 commit 1ed6a58
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 0 deletions.
47 changes: 47 additions & 0 deletions examples/typescript/src/__snapshots__/mix.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`matchers snapshot tests toMatchScreenReaderSnapshot on the whole body: toMatchScreenReaderSnapshot 1`] = `
[
"document",
"navigation",
"Nav Text",
"end of navigation",
"region",
"heading, First Section Heading, level 1",
"paragraph",
"First Section Text",
"end of paragraph",
"article",
"banner",
"heading, Article Header Heading, level 1",
"paragraph",
"Article Header Text",
"end of paragraph",
"end of banner",
"paragraph",
"Article Text",
"end of paragraph",
"end of article",
"end of region",
"region",
"heading, Second Section Heading, level 1",
"paragraph",
"Second Section Text",
"end of paragraph",
"end of region",
"contentinfo",
"Footer",
"end of contentinfo",
"end of document",
]
`;

exports[`matchers virtual screen reader tests navigating headings 1`] = `
[
"document",
"heading, First Section Heading, level 1",
"heading, Article Header Heading, level 1",
"heading, Second Section Heading, level 1",
"heading, First Section Heading, level 1",
]
`;
File renamed without changes.
60 changes: 60 additions & 0 deletions examples/typescript/src/mix.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { virtual } from "@guidepup/virtual-screen-reader";

function setupBasicPage() {
document.body.innerHTML = `
<nav>Nav Text</nav>
<section>
<h1>First Section Heading</h1>
<p>First Section Text</p>
<article>
<header>
<h1>Article Header Heading</h1>
<p>Article Header Text</p>
</header>
<p>Article Text</p>
</article>
</section>
<section>
<h1>Second Section Heading</h1>
<p>Second Section Text</p>
</section>
<section aria-hidden="true">
<h1>Hidden Section Heading</h1>
<p>Hidden Section Text</p>
</section>
<footer>Footer</footer>
`;
}

describe("matchers", () => {
beforeEach(() => {
setupBasicPage();
});

afterEach(() => {
document.body.innerHTML = ``;
});

describe("snapshot tests", () => {
test("toMatchScreenReaderSnapshot on the whole body", async () => {
await expect(document.body).toMatchScreenReaderSnapshot();
});
});

describe("virtual screen reader tests", () => {
test("navigating headings", async () => {
await virtual.start({ container: document.body });

await virtual.perform(virtual.commands.moveToNextHeading);
const firstHeadingPhrase = await virtual.lastSpokenPhrase();

do {
await virtual.perform(virtual.commands.moveToNextHeading);
} while ((await virtual.lastSpokenPhrase()) !== firstHeadingPhrase);

expect(await virtual.spokenPhraseLog()).toMatchSnapshot();

await virtual.stop();
});
});
});

0 comments on commit 1ed6a58

Please sign in to comment.