storybookjs / storybook

Storybook is the industry standard workshop for building, documenting, and testing UI components in isolation
https://storybook.js.org
MIT License
84.2k stars 9.26k forks source link

[Bug]: Using dates in expect statements with the interactions add-on causes Storybook to crash #24465

Open nicwells opened 1 year ago

nicwells commented 1 year ago

Describe the bug

Using dates in expect statements (from @storybook/jest) within interaction tests (@storybook/addon-interactions) causes storybook to crash when running in the browser, resulting in a blank screen and the following error in the console:

Uncaught TypeError: e.split is not a function or its return value is not iterable

image

The expect in the following play function causes the error for example:

  play: () => {
    const date1 = new Date(Date.UTC(2020, 8, 9));
    const date2 = new Date(Date.UTC(2020, 8, 9));
    expect(date1).toEqual(date2);
  }.

The tests pass when running in test-runner.

The error looks to originate from this line in @storybook/addon-interactions where the dates are being rendered for display in the addon-interactions panel (the split string function is being called on the date object): https://github.com/storybookjs/storybook/blob/e9f2e1f7112fc5e391b82ff2d871d3656f5cdfee/code/addons/interactions/src/components/MethodCall.tsx#L345

The error occurs in v7.4.6 and the latest, as in the reproduction linked to below. The error did not occur in v6.5.16 which we were previously on.

To Reproduce

This error occurs in v7.4.6 of Storybook, also in the latest as in the reproduction link below. The error did not occur in v6.5.16.

Line #35 of Button.stories.js in the reproduction results in the error (i.e. white screen and error in console):

https://stackblitz.com/edit/github-pjbwb9?file=stories%2FButton.stories.js

System

No response

Additional context

No response

bodograumann commented 5 months ago

Looks to me like this should be pretty easy to fix. What do you think, @shilman ?

shilman commented 4 months ago

@bodograumann Indeed! Anybody want to give this a go? PRs welcome and would be prioritized.

yann-combarnous commented 3 months ago

@bodograumann Indeed! Anybody want to give this a go? PRs welcome and would be prioritized.

PR opened, thx!