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

Feature Request: Ability to have snapshots be placed in a __snapshots__ folder when using mocha #27

Closed
itsdouges opened this issue Dec 7, 2017 · 4 comments

Comments

@itsdouges
Copy link
Contributor

Hi!

This would be quite nice if it's possible. This line looks promising: https://github.com/suchipi/chai-jest-snapshot/blob/master/src/buildConfigState.js#L19 but haven't looked into it much.

@suchipi
Copy link
Owner

suchipi commented Dec 7, 2017

You should be able to do it like this:

import path from "path";
import chai from "chai";
import chaiJestSnapshot from "chai-jest-snapshot";

chai.use(chaiJestSnapshot);

before(function() {
  chaiJestSnapshot.resetSnapshotRegistry();
});

beforeEach(function() {
  const { currentTest } = this;
  const filename = path.resolve(path.dirname(currentTest.file), "__snapshots__", path.basename(currentTest.file) + ".snap");
  chaiJestSnapshot.setFilename(filename);
  chaiJestSnapshot.setTestName(currentTest.fullTitle());
});

Depending on your use-case, you might have to also add code in the beforeEach callback to create the __snapshots__ folder if it doesn't exist.

@itsdouges
Copy link
Contributor Author

works a treat, thanks!

would be good to have this as a config option?

@suchipi
Copy link
Owner

suchipi commented Dec 8, 2017

Maybe if enough people request it, but since you can do it using setFilename and setTestName, I don't think it's strictly necessary.

@suchipi suchipi closed this as completed Dec 8, 2017
@nene
Copy link

nene commented Dec 18, 2017

Would be nice to have this documented in README.

Though, as I would expect this package is of interest for people migrating from Jest to Mocha, it would be nice to have a special config option for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants