diff --git a/packages/expect-puppeteer/src/__snapshots__/index.test.ts.snap b/packages/expect-puppeteer/src/__snapshots__/index.test.ts.snap new file mode 100644 index 00000000..f31e5b8b --- /dev/null +++ b/packages/expect-puppeteer/src/__snapshots__/index.test.ts.snap @@ -0,0 +1,3 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`expect-puppeteer should works with \`addSnapshotSerializer\` 1`] = `hello`; diff --git a/packages/expect-puppeteer/src/index.test.ts b/packages/expect-puppeteer/src/index.test.ts index 61cc253c..6952d84a 100644 --- a/packages/expect-puppeteer/src/index.test.ts +++ b/packages/expect-puppeteer/src/index.test.ts @@ -1,5 +1,11 @@ import { getDefaultOptions, setDefaultOptions } from "."; +expect.addSnapshotSerializer({ + print: () => "hello", + test: () => true, + serialize: () => "hello", +}); + describe("expect-puppeteer", () => { beforeEach(async () => { await page.goto(`http://localhost:${process.env.TEST_SERVER_PORT}`); @@ -16,6 +22,10 @@ describe("expect-puppeteer", () => { expect(200).toBe(200); }); + it("should works with `addSnapshotSerializer`", () => { + expect({ hello: "world" }).toMatchSnapshot(); + }); + it("should get and set default options", () => { expect(getDefaultOptions()).toEqual({ timeout: 500 }); setDefaultOptions({ timeout: 200 }); diff --git a/packages/expect-puppeteer/src/index.ts b/packages/expect-puppeteer/src/index.ts index 1f57e995..774b29c4 100644 --- a/packages/expect-puppeteer/src/index.ts +++ b/packages/expect-puppeteer/src/index.ts @@ -6,7 +6,7 @@ import { checkIsPage, PuppeteerInstance, } from "./utils"; -import { jestExpect, JestExpect } from "@jest/expect"; +import type { JestExpect } from "@jest/expect"; import { notToMatchTextContent } from "./matchers/notToMatchTextContent"; import { notToMatchElement } from "./matchers/notToMatchElement"; import { toClick } from "./matchers/toClick"; @@ -95,6 +95,9 @@ export type PuppeteerMatchers = | MatchersFromSet | MatchersFromSet; +// @ts-ignore +const jestExpect = global.expect as JestExpect; + const wrapMatcher = ( matcher: Matcher, instance: PuppeteerInstance