Skip to content

Commit 6529ff4

Browse files
authored
fix(options): add allowSizeMismatch arg
1 parent c7a9acb commit 6529ff4

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

__tests__/__snapshots__/index.spec.js.snap

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ exports[`toMatchImageSnapshot dumpDiffToConsole imgSrcString is not added to con
1414

1515
exports[`toMatchImageSnapshot passes diffImageToSnapshot everything it needs to create a snapshot and compare if needed 1`] = `
1616
Object {
17+
"allowSizeMismatch": false,
1718
"blur": 0,
1819
"customDiffConfig": Object {},
1920
"diffDir": "path/to/__image_snapshots__/__diff_output__",

__tests__/index.spec.js

+2
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ describe('toMatchImageSnapshot', () => {
408408
matcherAtTest();
409409

410410
expect(runDiffImageToSnapshot).toHaveBeenCalledWith({
411+
allowSizeMismatch: false,
411412
blur: 1,
412413
customDiffConfig: {
413414
perceptual: true,
@@ -464,6 +465,7 @@ describe('toMatchImageSnapshot', () => {
464465
matcherAtTest();
465466

466467
expect(diffImageToSnapshot).toHaveBeenCalledWith({
468+
allowSizeMismatch: false,
467469
blur: 0,
468470
customDiffConfig: {
469471
perceptual: true,

src/index.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ function checkResult({
3737
snapshotIdentifier,
3838
chalk,
3939
dumpDiffToConsole,
40+
allowSizeMismatch,
4041
}) {
4142
let pass = true;
4243
/*
@@ -65,7 +66,7 @@ function checkResult({
6566
const differencePercentage = result.diffRatio * 100;
6667
message = () => {
6768
let failure;
68-
if (result.diffSize) {
69+
if (result.diffSize && !allowSizeMismatch) {
6970
failure = `Expected image to be the same size as the snapshot (${result.imageDimensions.baselineWidth}x${result.imageDimensions.baselineHeight}), but was different (${result.imageDimensions.receivedWidth}x${result.imageDimensions.receivedHeight}).\n`;
7071
} else {
7172
failure = `Expected image to match or be a close match to snapshot but was ${differencePercentage}% different from snapshot (${result.diffPixelCount} differing pixels).\n`;
@@ -134,6 +135,7 @@ function configureToMatchImageSnapshot({
134135
blur: commonBlur = 0,
135136
runInProcess: commonRunInProcess = false,
136137
dumpDiffToConsole: commonDumpDiffToConsole = false,
138+
allowSizeMismatch: commonAllowSizeMismatch = false,
137139
} = {}) {
138140
return function toMatchImageSnapshot(received, {
139141
customSnapshotIdentifier = commonCustomSnapshotIdentifier,
@@ -148,6 +150,7 @@ function configureToMatchImageSnapshot({
148150
blur = commonBlur,
149151
runInProcess = commonRunInProcess,
150152
dumpDiffToConsole = commonDumpDiffToConsole,
153+
allowSizeMismatch = commonAllowSizeMismatch,
151154
} = {}) {
152155
const {
153156
testPath, currentTestName, isNot, snapshotState,
@@ -196,6 +199,7 @@ function configureToMatchImageSnapshot({
196199
failureThresholdType,
197200
updatePassedSnapshot,
198201
blur,
202+
allowSizeMismatch,
199203
});
200204

201205
return checkResult({
@@ -205,6 +209,7 @@ function configureToMatchImageSnapshot({
205209
snapshotIdentifier,
206210
chalk,
207211
dumpDiffToConsole,
212+
allowSizeMismatch,
208213
});
209214
};
210215
}

0 commit comments

Comments
 (0)