Skip to content

Commit

Permalink
Use testFailing to determine matching behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
KhaledElmorsy committed Oct 2, 2023
1 parent 8ac6139 commit ad2b713
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
6 changes: 3 additions & 3 deletions packages/jest-snapshot/src/State.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export type SnapshotMatchOptions = {
readonly inlineSnapshot?: string;
readonly isInline: boolean;
readonly error?: Error;
readonly matchOnly?: boolean;
readonly testFailing?: boolean;
};

type SnapshotReturnOptions = {
Expand Down Expand Up @@ -198,7 +198,7 @@ export default class SnapshotState {
inlineSnapshot,
isInline,
error,
matchOnly = false,
testFailing = false,
}: SnapshotMatchOptions): SnapshotReturnOptions {
this._counters.set(testName, (this._counters.get(testName) || 0) + 1);
const count = Number(this._counters.get(testName));
Expand Down Expand Up @@ -234,7 +234,7 @@ export default class SnapshotState {

// In pure matching only runs, return the match result while skipping any updates
// reports.
if (matchOnly) {
if (testFailing) {
if (hasSnapshot && !isInline) {
// Retain current snapshot values.
this._addSnapshot(key, expected, {error, isInline});
Expand Down
14 changes: 2 additions & 12 deletions packages/jest-snapshot/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,17 +281,7 @@ const _toMatchSnapshot = (config: MatchSnapshotConfig) => {
/** If a test was ran with `test.failing`. Passed by Jest Circus. */
const {testFailing = false} = context;

/**
* Run the snapshot matcher as a normal throwing matcher with
* no side effects and no error supression.
*
* Skipped side effects occur in {@link snapshotState.match}
* and include updating the snapshot and recording passed/failed
* snapshots in the snapshot state.
*/
const matchOnly = testFailing;

if (!matchOnly && context.dontThrow) {
if (!testFailing && context.dontThrow) {
// Supress errors while running tests
context.dontThrow();
}
Expand Down Expand Up @@ -375,8 +365,8 @@ const _toMatchSnapshot = (config: MatchSnapshotConfig) => {
error: context.error,
inlineSnapshot,
isInline,
matchOnly,
received,
testFailing,
testName: fullTestName,
});
const {actual, count, expected, pass} = result;
Expand Down

0 comments on commit ad2b713

Please sign in to comment.