Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(snapshot): concatenate name of test and snapshot #4460

Merged
merged 5 commits into from
Oct 10, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions packages/jest-snapshot/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@ import type {Path, SnapshotUpdateState} from 'types/Config';
import fs from 'fs';
import path from 'path';
import diff from 'jest-diff';
import {
EXPECTED_COLOR,
ensureNoExpected,
matcherHint,
RECEIVED_COLOR,
} from 'jest-matcher-utils';
import {EXPECTED_COLOR, matcherHint, RECEIVED_COLOR} from 'jest-matcher-utils';
import SnapshotState from './State';
import {addSerializer, getSerializers} from './plugins';
import {SNAPSHOT_EXTENSION} from './utils';
Expand Down Expand Up @@ -68,7 +63,7 @@ const toMatchSnapshot = function(received: any, testName?: string) {
}

const result = snapshotState.match(
testName || currentTestName || '',
testName ? `${currentTestName}: ${testName}` : currentTestName || '',
received,
);
const {count, pass} = result;
Expand Down Expand Up @@ -116,7 +111,10 @@ const toMatchSnapshot = function(received: any, testName?: string) {
};
};

const toThrowErrorMatchingSnapshot = function(received: any, expected: void) {
const toThrowErrorMatchingSnapshot = function(
received: any,
testName?: string,
) {
this.dontThrow && this.dontThrow();
const {isNot} = this;

Expand All @@ -126,8 +124,6 @@ const toThrowErrorMatchingSnapshot = function(received: any, expected: void) {
);
}

ensureNoExpected(expected, '.toThrowErrorMatchingSnapshot');

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain why it is removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because expected now is the testName

let error;

try {
Expand All @@ -145,7 +141,7 @@ const toThrowErrorMatchingSnapshot = function(received: any, expected: void) {
);
}

return toMatchSnapshot.call(this, error.message);
return toMatchSnapshot.call(this, error.message, testName);
};

module.exports = {
Expand Down