diff --git a/__tests__/diff-snapshot.spec.js b/__tests__/diff-snapshot.spec.js index bb5a868..e635fcd 100644 --- a/__tests__/diff-snapshot.spec.js +++ b/__tests__/diff-snapshot.spec.js @@ -693,6 +693,22 @@ describe('diff-snapshot', () => { expect(diffResult).toHaveProperty('diffOutputPath', path.join(mockSnapshotsDir, '__diff_output__', `${mockSnapshotIdentifier}-diff.png`)); }); + describe('diffImageToSnapshot', () => { + it('should fail if snapshot already exists', () => { + const { diffImageToSnapshot } = setupTest({ snapshotExists: true }); + const options = { + receivedImageBuffer: mockFailImageBuffer, + snapshotIdentifier: mockSnapshotIdentifier, + snapshotsDir: mockSnapshotsDir, + updateSnapshot: false, + }; + + expect(() => { + diffImageToSnapshot(options); + }).toThrow(); + }); + }); + it('should throw an error if an unknown threshold type is supplied', () => { const diffImageToSnapshot = setupTest({ snapshotExists: true }); diff --git a/package-lock.json b/package-lock.json index 371a51d..4250e8a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11785,4 +11785,4 @@ "dev": true } } -} +} \ No newline at end of file diff --git a/src/diff-snapshot.js b/src/diff-snapshot.js index aa3c62c..8ce841b 100644 --- a/src/diff-snapshot.js +++ b/src/diff-snapshot.js @@ -147,9 +147,8 @@ const alignImagesToSameSize = (firstImage, secondImage) => { const isFailure = ({ pass, updateSnapshot }) => !pass && !updateSnapshot; -const shouldUpdate = ({ pass, updateSnapshot, updatePassedSnapshot }) => ( - (!pass && updateSnapshot) || (pass && updatePassedSnapshot) -); +const shouldUpdate = ({ pass, updateSnapshot, updatePassedSnapshot }) => + updateSnapshot && (!pass || (pass && updatePassedSnapshot)); const shouldFail = ({ totalPixels,