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

Allow name to be provided to toMatchSnapshot #92

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
22 changes: 17 additions & 5 deletions src/target.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,24 +200,36 @@ export default class Target {
}
}

async toMatchSnapshot(image, callback) {
async toMatchSnapshot(image, callback, settings) {
Copy link
Owner

Choose a reason for hiding this comment

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

I wonder if we could move all these sanitizations to a separate function like sanitiseToMatchSnapshotArg()?!

let resultCallback;
if (image && !isFunc(image)) {
let providedName = false;
if (image && !isFunc(image) && !image.name) {
this.image = image;
} else if (isFunc(image)) {
resultCallback = image;
} else if (image && image.name) {
providedName = image.name;
}
if (callback && isFunc(callback)) {
resultCallback = callback;
} else if (callback && callback.name) {
providedName = callback.name;
}
if (settings && settings.name) {
providedName = settings.name;
}
if (this.testConfig.isJest && !this.testConfig.testNameProvided) {
this.testConfig.testName = this.testId
? `${this.testStats.currentTestName} ${this.testId}`
: this.testStats.currentTestName;
} else {
this.testConfig.testName = this.testId
? `${this.testConfig.testName} ${this.testId}`
: this.testConfig.testName;
if (providedName) {
this.testConfig.testName = providedName;
} else {
this.testConfig.testName = this.testId
? `${this.testConfig.testName} ${this.testId}`
: this.testConfig.testName;
}
}
this.testId += 1;
const result = await this._evaluateResult();
Expand Down