Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Jest snapshot resolver for snapshots at top level of repo when tests are in component folders.
const path = require('path')
const rootDir = path.resolve(__dirname, '..')
module.exports = {
/** resolves from test to snapshot path */
resolveSnapshotPath: (testPath, snapshotExtension) => {
return testPath.replace('src/', '__snapshots__/') + snapshotExtension
},
/** resolves from snapshot to test path */
resolveTestPath: (snapshotFilePath, snapshotExtension) => {
return snapshotFilePath
.replace('__snapshots__/', 'src/')
.slice(0, -snapshotExtension.length)
}
}
@aliankarali

This comment has been minimized.

Copy link

aliankarali commented Feb 28, 2019

Nice. Needed to add testPathForConsistencyCheck: 'some/__tests__/example.test.js', at the end though (Jest 24.1.0).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.