Skip to content

Commit 826fd31

Browse files
committed
fix(expect-puppeteer): fix addSnapshotSerializer usage
Closes #552
1 parent d7d9833 commit 826fd31

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`expect-puppeteer should works with \`addSnapshotSerializer\` 1`] = `hello`;

packages/expect-puppeteer/src/index.test.ts

+10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import { getDefaultOptions, setDefaultOptions } from ".";
22

3+
expect.addSnapshotSerializer({
4+
print: () => "hello",
5+
test: () => true,
6+
serialize: () => "hello",
7+
});
8+
39
describe("expect-puppeteer", () => {
410
beforeEach(async () => {
511
await page.goto(`http://localhost:${process.env.TEST_SERVER_PORT}`);
@@ -16,6 +22,10 @@ describe("expect-puppeteer", () => {
1622
expect(200).toBe(200);
1723
});
1824

25+
it("should works with `addSnapshotSerializer`", () => {
26+
expect({ hello: "world" }).toMatchSnapshot();
27+
});
28+
1929
it("should get and set default options", () => {
2030
expect(getDefaultOptions()).toEqual({ timeout: 500 });
2131
setDefaultOptions({ timeout: 200 });

packages/expect-puppeteer/src/index.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
checkIsPage,
77
PuppeteerInstance,
88
} from "./utils";
9-
import { jestExpect, JestExpect } from "@jest/expect";
9+
import type { JestExpect } from "@jest/expect";
1010
import { notToMatchTextContent } from "./matchers/notToMatchTextContent";
1111
import { notToMatchElement } from "./matchers/notToMatchElement";
1212
import { toClick } from "./matchers/toClick";
@@ -95,6 +95,9 @@ export type PuppeteerMatchers =
9595
| MatchersFromSet<PageMatchers>
9696
| MatchersFromSet<ElementHandleMatchers>;
9797

98+
// @ts-ignore
99+
const jestExpect = global.expect as JestExpect;
100+
98101
const wrapMatcher = <TPage extends PuppeteerInstance>(
99102
matcher: Matcher<TPage>,
100103
instance: PuppeteerInstance

0 commit comments

Comments
 (0)