Skip to content

Commit 3e72ec8

Browse files
authored
🤖 Merge PR DefinitelyTyped#74206 fix: [jest-image-snapshot] use real signature by @dword-design
1 parent 67a877f commit 3e72ec8

File tree

4 files changed

+100
-13
lines changed

4 files changed

+100
-13
lines changed

‎types/jest-image-snapshot/index.d.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,10 @@ export interface MatchImageSnapshotOptions {
134134
* import { toMatchImageSnapshot } from 'jest-image-snapshot';
135135
* expect.extend({ toMatchImageSnapshot });
136136
*/
137-
export function toMatchImageSnapshot(options?: MatchImageSnapshotOptions): { message(): string; pass: boolean };
137+
export function toMatchImageSnapshot(
138+
received: Buffer,
139+
options?: MatchImageSnapshotOptions,
140+
): { message(): string; pass: boolean };
138141

139142
/**
140143
* Configurable function that can be passed to jest's expect.extend.
@@ -145,7 +148,7 @@ export function toMatchImageSnapshot(options?: MatchImageSnapshotOptions): { mes
145148
*/
146149
export function configureToMatchImageSnapshot(
147150
options: MatchImageSnapshotOptions,
148-
): () => { message(): string; pass: boolean };
151+
): (received: Buffer, options?: MatchImageSnapshotOptions) => { message(): string; pass: boolean };
149152

150153
/**
151154
* Mutates original state with new state

‎types/jest-image-snapshot/jest-image-snapshot-tests.ts‎

Lines changed: 93 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,24 @@ import {
44
toMatchImageSnapshot,
55
updateSnapshotState,
66
} from "jest-image-snapshot";
7+
import sharp from "sharp";
78

8-
it("should be able to use toMatchImageSnapshot in a test", () => {
9+
it("should be able to use toMatchImageSnapshot in a test", async () => {
910
expect.extend({ toMatchImageSnapshot });
1011

11-
expect(400).toMatchImageSnapshot();
12+
expect(
13+
await sharp({
14+
create: {
15+
background: { b: 0, g: 255, r: 0 },
16+
channels: 3,
17+
height: 48,
18+
width: 48,
19+
},
20+
}).png().toBuffer(),
21+
).toMatchImageSnapshot();
1222
});
1323

14-
it("should be able to use configureToMatchImageSnapshot in a test", () => {
24+
it("should be able to use configureToMatchImageSnapshot in a test", async () => {
1525
const matchFn = configureToMatchImageSnapshot({
1626
allowSizeMismatch: true,
1727
noColors: true,
@@ -25,10 +35,19 @@ it("should be able to use configureToMatchImageSnapshot in a test", () => {
2535
});
2636
expect.extend({ toMatchImageSnapshot: matchFn });
2737

28-
expect("Me").toMatchImageSnapshot();
38+
expect(
39+
await sharp({
40+
create: {
41+
background: { b: 0, g: 255, r: 0 },
42+
channels: 3,
43+
height: 48,
44+
width: 48,
45+
},
46+
}).png().toBuffer(),
47+
).toMatchImageSnapshot();
2948
});
3049

31-
it("Should be able to use configuration directly in toMatchImageSnapshot", () => {
50+
it("Should be able to use configuration directly in toMatchImageSnapshot", async () => {
3251
expect.extend({ toMatchImageSnapshot });
3352

3453
const options: MatchImageSnapshotOptions = {
@@ -52,27 +71,91 @@ it("Should be able to use configuration directly in toMatchImageSnapshot", () =>
5271
failureThresholdType: "percent",
5372
};
5473

55-
expect("Me").toMatchImageSnapshot(options);
74+
expect(
75+
await sharp({
76+
create: {
77+
background: { b: 0, g: 255, r: 0 },
78+
channels: 3,
79+
height: 48,
80+
width: 48,
81+
},
82+
}).png().toBuffer(),
83+
).toMatchImageSnapshot(options);
5684
});
5785

58-
it("Should be able to use string as customSnapshotIdentifier", () => {
86+
it("Should be able to use string as customSnapshotIdentifier", async () => {
5987
const options: MatchImageSnapshotOptions = {
6088
customSnapshotIdentifier: "string identifier",
6189
};
6290

63-
expect("Me").toMatchImageSnapshot(options);
91+
expect(
92+
await sharp({
93+
create: {
94+
background: { b: 0, g: 255, r: 0 },
95+
channels: 3,
96+
height: 48,
97+
width: 48,
98+
},
99+
}).png().toBuffer(),
100+
).toMatchImageSnapshot(options);
64101
});
65102

66-
it("Should be able to use callback as customSnapshotIdentifier", () => {
103+
it("Should be able to use callback as customSnapshotIdentifier", async () => {
67104
const options: MatchImageSnapshotOptions = {
68105
customSnapshotIdentifier: () => "string identifier",
69106
};
70107

71-
expect("Me").toMatchImageSnapshot(options);
108+
expect(
109+
await sharp({
110+
create: {
111+
background: { b: 0, g: 255, r: 0 },
112+
channels: 3,
113+
height: 48,
114+
width: 48,
115+
},
116+
}).png().toBuffer(),
117+
).toMatchImageSnapshot(options);
72118
});
73119

74120
it("mutates original state", () => {
75121
const originalState = { some: "value" };
76122
updateSnapshotState(originalState, { another: "val" });
77123
expect(originalState).toEqual({ some: "value", another: "val" });
78124
});
125+
126+
it("should be able to use toMatchImageSnapshot without expect", async () => {
127+
const result = toMatchImageSnapshot.call(
128+
expect.getState(),
129+
await sharp({
130+
create: {
131+
background: { b: 0, g: 255, r: 0 },
132+
channels: 3,
133+
height: 48,
134+
width: 48,
135+
},
136+
}).png().toBuffer(),
137+
{
138+
allowSizeMismatch: true,
139+
},
140+
);
141+
expect(result.pass).toEqual(true);
142+
});
143+
144+
it("should be able to use configureToMatchImageSnapshot without expect", async () => {
145+
const matchFn = configureToMatchImageSnapshot({
146+
allowSizeMismatch: true,
147+
});
148+
149+
const result = matchFn.call(
150+
expect.getState(),
151+
await sharp({
152+
create: {
153+
background: { b: 0, g: 255, r: 0 },
154+
channels: 3,
155+
height: 48,
156+
width: 48,
157+
},
158+
}).png().toBuffer(),
159+
);
160+
expect(result.pass).toEqual(true);
161+
});

‎types/jest-image-snapshot/package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"ssim.js": "^3.1.1"
1212
},
1313
"devDependencies": {
14-
"@types/jest-image-snapshot": "workspace:."
14+
"@types/jest-image-snapshot": "workspace:.",
15+
"sharp": "*"
1516
},
1617
"owners": [
1718
{

‎types/jest-image-snapshot/stubs/runtimeHooksPath.js‎

Whitespace-only changes.

0 commit comments

Comments
 (0)