Skip to content
Merged
16 changes: 16 additions & 0 deletions __tests__/diff-snapshot.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions src/diff-snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) =>
Comment thread
goverdhan07 marked this conversation as resolved.
updateSnapshot && (!pass || (pass && updatePassedSnapshot));

const shouldFail = ({
totalPixels,
Expand Down