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

Action function is not spied in chromatic interaction #606

Closed
swallowtail62 opened this issue Jul 15, 2022 · 2 comments
Closed

Action function is not spied in chromatic interaction #606

swallowtail62 opened this issue Jul 15, 2022 · 2 comments

Comments

@swallowtail62
Copy link

As mentioned in the following link, In local storybook action mock works.

https://github.com/storybookjs/storybook/tree/v6.5.9/addons/interactions#usage

Any args that are marked as an action (typically via argTypes or argTypesRegex) will be automatically wrapped in a Jest mock function so you can assert invocations. See addon-actions for how to setup actions.

However in chromatic, mock don't work and test fails. Error as shown in the following.

image

Error: expect(received).toBeCalledTimes(expected)

Matcher error: received value must be a mock or spy function

Received has type:  function
Received has value: [Function n]
@tmeasday
Copy link
Member

Hey @swallowtail62 -- have you tried in your built storybook? I would expect Chromatic's behaviour would be very similar to ejecting from the build.

@swallowtail62
Copy link
Author

swallowtail62 commented Jul 15, 2022

Sorry, it wasn't chromatic.
It was because initialArgs property (function) name had been shortened in built storybook.

image

The name had to be actionHandler.

https://github.com/storybookjs/storybook/blob/v6.5.9/addons/interactions/src/preset/preview.ts#L23

I'm using @storybook/builder-vite as a bulder so I'll take a look there, thanks.

-- updated --
The issue had already been raised.

storybookjs/builder-vite#206

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

2 participants