Skip to content

Commit b9d9c3f

Browse files
fix: only updatePassedSnapshot if updateSnapshot is also true (#327)
* chore(deps): bump qs from 6.5.2 to 6.5.3 (#320) * chore(deps): make jest optional peerDependency (#322) * chore(deps): bump http-cache-semantics from 4.1.0 to 4.1.1 (#324) Bumps [http-cache-semantics](https://github.com/kornelski/http-cache-semantics) from 4.1.0 to 4.1.1. - [Release notes](https://github.com/kornelski/http-cache-semantics/releases) - [Commits](kornelski/http-cache-semantics@v4.1.0...v4.1.1) --- updated-dependencies: - dependency-name: http-cache-semantics dependency-type: indirect ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * fix: updatePassedSnapshot to only update passed snapshots when jest --updatesnapshot flag is present * fix: fixed indentations * fix: added unit test case * removed package.json file * Revert "removed package.json file" This reverts commit 6cf2343. --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent ce33742 commit b9d9c3f

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

__tests__/diff-snapshot.spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,22 @@ describe('diff-snapshot', () => {
693693
expect(diffResult).toHaveProperty('diffOutputPath', path.join(mockSnapshotsDir, '__diff_output__', `${mockSnapshotIdentifier}-diff.png`));
694694
});
695695

696+
describe('diffImageToSnapshot', () => {
697+
it('should fail if snapshot already exists', () => {
698+
const { diffImageToSnapshot } = setupTest({ snapshotExists: true });
699+
const options = {
700+
receivedImageBuffer: mockFailImageBuffer,
701+
snapshotIdentifier: mockSnapshotIdentifier,
702+
snapshotsDir: mockSnapshotsDir,
703+
updateSnapshot: false,
704+
};
705+
706+
expect(() => {
707+
diffImageToSnapshot(options);
708+
}).toThrow();
709+
});
710+
});
711+
696712
it('should throw an error if an unknown threshold type is supplied', () => {
697713
const diffImageToSnapshot = setupTest({ snapshotExists: true });
698714

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/diff-snapshot.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,8 @@ const alignImagesToSameSize = (firstImage, secondImage) => {
147147

148148
const isFailure = ({ pass, updateSnapshot }) => !pass && !updateSnapshot;
149149

150-
const shouldUpdate = ({ pass, updateSnapshot, updatePassedSnapshot }) => (
151-
(!pass && updateSnapshot) || (pass && updatePassedSnapshot)
152-
);
150+
const shouldUpdate = ({ pass, updateSnapshot, updatePassedSnapshot }) =>
151+
updateSnapshot && (!pass || (pass && updatePassedSnapshot));
153152

154153
const shouldFail = ({
155154
totalPixels,

0 commit comments

Comments
 (0)