-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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
[Bug]: TypeError: expect.extend
error in Jest when using @storybook/jest
's expect()
in related stories
#24194
Comments
Same problem, I just have written a bunch of stories exactly like the official doc says, e.x. https://storybook.js.org/docs/react/writing-stories/play-function here is the log: TypeError: Cannot read properties of undefined (reading 'location')
at instrument (/path/to/project1/node_modules/@storybook/jest/dist/index.js:385:37)
at Object.<anonymous> (/path/to/project1/node_modules/@storybook/jest/dist/index.js:392:121)
at Module._compile (node:internal/modules/cjs/loader:1257:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1311:10)
at Object.newLoader (/path/to/project1/node_modules/esbuild-register/dist/node.js:2262:9)
at extensions..js (/path/to/project1/node_modules/esbuild-register/dist/node.js:4807:24)
at Module.load (node:internal/modules/cjs/loader:1115:32)
at Module._load (node:internal/modules/cjs/loader:962:12)
at Module.require (node:internal/modules/cjs/loader:1139:19)
at require (node:internal/modules/helpers:121:18)
WARN Failed to load preset: {"type":"presets","name":"/path/to/project1/node_modules/@storybook/jest/dist/index.js"} on level 1
TypeError: expect.extend: `default` is not a valid matcher. Must be a function, is "object"
at ./node_modules/@storybook/expect/dist/index.js:1:132723
at Array.forEach (<anonymous>)
at t.setMatchers (./node_modules/@storybook/expect/dist/index.js:1:132667)
at v.extend (./node_modules/@storybook/expect/dist/index.js:1:130447)
at Object.<anonymous> (./node_modules/@storybook/jest/dist/index.js:396:8)
at Module._compile (node:internal/modules/cjs/loader:1257:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1311:10)
at Object.newLoader (./node_modules/esbuild-register/dist/node.js:2262:9)
at extensions..js (./node_modules/esbuild-register/dist/node.js:4807:24)
at Module.load (node:internal/modules/cjs/loader:1115:32) |
A temporary fix (until this issue is resolved) is to pin - "@storybook/jest": "^0.2.2",
+ "@storybook/jest": "0.2.1", |
same here |
Chromatic [tests were failing](https://github.com/cfpb/design-system-react/actions/runs/6433456084/job/17470552029?pr=194#step:5:143) with a weird `Error: page.evaluate: TypeError: expect.extend: `default` is not a valid matcher. Must be a function, is "object"` error. ## Changes - updates the version for `"@storybook/jest"` to `"^0.2.2",` to fix a bug with the jest/storybook integration ([see the issue thread](storybookjs/storybook#24194)) ## How to test this PR 1. Make sure storybook still works as intended 2. Note that chromatic no longer fails in CI on this PR ## Screenshots <img width="1264" alt="Screenshot 2023-10-11 at 7 35 34 AM" src="https://github.com/cfpb/design-system-react/assets/19983248/4f6a9212-ffbf-41d2-bc2c-e219b8c9131d">
@IanVS Do you have any idea about this? @raybrownco Could you check if 0.2.3 solves the problem? |
@kasperpeulen I'm working at a different org now, so I don't have access to the projects that I originally ran into this issue with. However, I just opened the Stackblitz repro and updated the version from |
@raybrownco @kasperpeulen @nodegin @IanVS I guess this issue can be closed, not sure thought if they are 100% same issue. Look at this discussion here: #25093 |
I just tested this issue again with |
This may help with the storybook issue for squared and the GafaelfawrUserMenu. storybookjs/storybook#24194
Describe the bug
I've run into an interesting bug related to the
composeStories()
method from@storybook/react
, theexpect()
method from@storybook/jest@0.2.2
, and Jest test suites that consume Storybook stories. This bug affects several of my company's front-end projects, each of which is a TypeScript React project that uses Jest/RTL for unit tests. I've narrowed down the bug to an isolated experience, which I've been able to reproduce in StackBlitz.The issue occurs when:
@storybook/jest
'sexpect
method, starting with@storybook/jestv0.2.2
composeStories
methodexpect()
method) on the Play function storiesPlease see the reproduction instructions and system info below. If you need any other information, please let me know - I'd love to help in any way that I can!
To Reproduce
yarn
to install dependencies (if needed - this should happen automatically)yarn storybook
and wait for the UI to loadyarn test
src/foo-component/index.stories.tsx
await expect
(there should be six of them, all within the Play functions)yarn test
System
Additional context
No response
The text was updated successfully, but these errors were encountered: