Skip to content

Commit

Permalink
fix(expect-puppeteer): fix addSnapshotSerializer usage
Browse files Browse the repository at this point in the history
Closes #552
  • Loading branch information
gregberge committed May 24, 2023
1 parent d7d9833 commit 826fd31
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`expect-puppeteer should works with \`addSnapshotSerializer\` 1`] = `hello`;
10 changes: 10 additions & 0 deletions packages/expect-puppeteer/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -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}`);
Expand All @@ -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 });
Expand Down
5 changes: 4 additions & 1 deletion packages/expect-puppeteer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -95,6 +95,9 @@ export type PuppeteerMatchers =
| MatchersFromSet<PageMatchers>
| MatchersFromSet<ElementHandleMatchers>;

// @ts-ignore
const jestExpect = global.expect as JestExpect;

const wrapMatcher = <TPage extends PuppeteerInstance>(
matcher: Matcher<TPage>,
instance: PuppeteerInstance
Expand Down

0 comments on commit 826fd31

Please sign in to comment.