After updating to latest version of jest initStoryshots() fails:
Test suite failed to run
testStorySnapshots is intended only to be used inside jest
at testStorySnapshots (node_modules/@storybook/addon-storyshots/dist/index.js:114:11)
I'm not sure if this is due to jest update since we went from version 19.x to 21.x.
From package.json:
"@storybook/addon-storyshots": "^3.2.12"
"@storybook/react": "^3.2.12"
"babel-jest": "^21.2.0"
"jest": "^21.2.1"
__ test __/storyshots.test.js
import initStoryshots from '@storybook/addon-storyshots';
initStoryshots();
When I check inside index.js:114:11 the _global is empty object {}.
Not sure if this helps but if I add
_global.describe = global.describe;
_global.it = global.it;
_global.window = global.window;
before
if (typeof _global.describe !== 'function') {
throw new Error('testStorySnapshots is intended only to be used inside jest');
}
it works.
Hi,
So the reason is that in our project there is a file called global at the root of our project.
This root is defined in webpack resolve so we can import it without writing relative paths.
storyshots is relying on a library called global. Webpack imports our global file instead of the library.
Sorry not webpack resolve but jest equivalent modulePaths
As mentioned by @florian-bd it was due to a configuration issue in our project, and as we tried setting up a minimal project with webpack, jest, storybook and storyshots it worked well. So, closing this issue.
I too had this with react native.
Anyone have any ideas?
My fix was to jest.mock global so the require global in storyshots got the real jest global.
import initStoryshots, {
multiSnapshotWithOptions,
} from '@storybook/addon-storyshots';
jest.mock('global', () => global);
initStoryshots({
configPath: 'src/test/Storybook',
test: multiSnapshotWithOptions({}),
});
Most helpful comment
I too had this with react native.
Anyone have any ideas?
My fix was to jest.mock global so the require global in storyshots got the real jest global.