Storybook: ReferenceError: window is not defined when executing initStoryshots()

Created on 17 Apr 2017  ·  6Comments  ·  Source: storybookjs/storybook

When using jest to init initStoryshots (as per the guide), I am stumped with the following error. Sadly all of the code references that used to exist for storyshots seem to go to 404 pages.

` FAIL .\Storyshots._test_.js
● Test suite failed to run

ReferenceError: window is not defined

  at evalmachine.<anonymous>:17:1
  at runWithRequireContext (node_modules\storyshots\dist\require_context.js:104:3)
  at testStorySnapshots (node_modules\storyshots\dist\index.js:72:35)
  at Object.<anonymous> (Storyshots._test_.js:2:26)
  at process._tickCallback (internal\process\next_tick.js:109:7)`
needs reproduction question / support

Most helpful comment

Found the solution is that unlike in some other jest setups, you need to define your windows as global objects in the config file.

All 6 comments

@flanamacca which code references are you referring to? The storyshots repo has moved here:

https://github.com/storybooks/storybook/tree/master/packages/storyshots

We are in the process of transitioning to a mono-repo to simplify version management and testing.

Hey @shilman This part on that pge.

import initStoryshots from 'storyshots';
initStoryshots();