From 2c98758873b4c34aca2f05a969aec6c0ec7b5883 Mon Sep 17 00:00:00 2001 From: jlp-craigmorten Date: Wed, 28 Feb 2024 09:14:31 +0000 Subject: [PATCH] fix: snapshots get their own virtual screen reader fix: correct the minimum @guidepup/virtual-screen-reader peer dep version --- package.json | 4 ++-- src/__snapshots__/index.test.ts.snap | 9 +++++++++ src/index.test.ts | 17 +++++++++++++++++ src/index.ts | 4 +++- 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 208adf4..261e273 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@guidepup/jest", - "version": "0.3.2", + "version": "0.3.3", "description": "Virtual Screen Reader Jest Matchers", "main": "lib/index.js", "author": "Craig Morten ", @@ -34,7 +34,7 @@ "jest-snapshot": "^29.7.0" }, "peerDependencies": { - "@guidepup/virtual-screen-reader": "^0.16.1", + "@guidepup/virtual-screen-reader": "^0.14.0", "jest": "^29" }, "devDependencies": { diff --git a/src/__snapshots__/index.test.ts.snap b/src/__snapshots__/index.test.ts.snap index 488f22a..7293ea5 100644 --- a/src/__snapshots__/index.test.ts.snap +++ b/src/__snapshots__/index.test.ts.snap @@ -1,5 +1,14 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`matchers snapshot matchers handles parallel assertions: toMatchScreenReaderSnapshot 1`] = ` +[ + "region", + "heading, Second Section Heading, level 1", + "Second Section Text", + "end of region", +] +`; + exports[`matchers toMatchScreenReaderSnapshot on a hidden node: toMatchScreenReaderSnapshot 1`] = `[]`; exports[`matchers toMatchScreenReaderSnapshot on a null node: toMatchScreenReaderSnapshot 1`] = `[]`; diff --git a/src/index.test.ts b/src/index.test.ts index 2b945df..07af279 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -121,4 +121,21 @@ describe("matchers", () => { test("toMatchScreenReaderInlineSnapshot on a null node", async () => { await expect(null).toMatchScreenReaderInlineSnapshot(`[]`); }); + + test("snapshot matchers handles parallel assertions", async () => { + await Promise.all([ + expect( + document.getElementsByTagName("section")[1] + ).toMatchScreenReaderSnapshot(), + expect(document.getElementsByTagName("section")[1]) + .toMatchScreenReaderInlineSnapshot(` +[ + "region", + "heading, Second Section Heading, level 1", + "Second Section Text", + "end of region", +] +`), + ]); + }); }); diff --git a/src/index.ts b/src/index.ts index d66ccd7..ff82425 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,5 @@ import { toMatchInlineSnapshot, toMatchSnapshot } from "jest-snapshot"; -import { virtual } from "@guidepup/virtual-screen-reader"; +import { Virtual } from "@guidepup/virtual-screen-reader"; // REF: https://jestjs.io/docs/en/expect.html#expectextendmatchers declare global { @@ -19,6 +19,8 @@ if (expect?.extend !== undefined) { } async function getScreenReaderOutput(container) { + const virtual = new Virtual(); + let spokenPhraseLog: string[] = []; try {