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

[Bug]: toHaveBeenCalledWith does not display expected / received values on failure #26934

Open
jacobleetodd opened this issue Apr 23, 2024 · 1 comment
Assignees

Comments

@jacobleetodd
Copy link

Describe the bug

If a test expects a mock function to have been called with a specific object, and the correct object is not received, the expected and received values are both shown as undefined. In the previous version of Storybook the delta between expected and received was displayed.

To Reproduce

import { expect, fn, userEvent, waitFor, within } from "@storybook/test";

export const ClickButton: Story = {
  args: { handleButtonClick: fn(), id: 1 },
  play: async ({ args, canvasElement }) => {
    const canvas = within(canvasElement);

    await userEvent.click(canvas.getByRole("button"));
    await waitFor(() =>
      // NOTE: expecting the wrong id
      expect(args.handleButtonClick).toHaveBeenCalledWith({ { id: 2 } }),
    );
  },
};

// NOTE: error seen in the interactions tab:
expect(spy).toHaveBeenCalledWith({ id: 1 } })
expected "spy" to be called with arguments: [ { id: 1 } ]

Expected: undefined
Received: undefined
See the full stack trace in the browser console.

System

Storybook Environment Info:

  System:
    OS: macOS 14.3
    CPU: (12) arm64 Apple M2 Pro
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.10.0 - ~/.nvm/versions/node/v20.10.0/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - ~/.nvm/versions/node/v20.10.0/bin/npm
    pnpm: 8.11.0 - ~/.nvm/versions/node/v20.10.0/bin/pnpm <----- active
  Browsers:
    Chrome: 124.0.6367.62
    Safari: 17.3
  npmPackages:
    @storybook/addon-a11y: 8.0.8 => 8.0.8 
    @storybook/addon-actions: 8.0.8 => 8.0.8 
    @storybook/addon-coverage: 1.0.1 => 1.0.1 
    @storybook/addon-essentials: 8.0.8 => 8.0.8 
    @storybook/addon-interactions: 8.0.8 => 8.0.8 
    @storybook/addon-links: 8.0.8 => 8.0.8 
    @storybook/addon-storysource: 8.0.8 => 8.0.8 
    @storybook/blocks: 8.0.8 => 8.0.8 
    @storybook/manager-api: 8.0.8 => 8.0.8 
    @storybook/react: 8.0.8 => 8.0.8 
    @storybook/react-vite: 8.0.8 => 8.0.8 
    @storybook/test: 8.0.8 => 8.0.8 
    @storybook/test-runner: 0.17.0 => 0.17.0 
    @storybook/theming: 8.0.8 => 8.0.8 
    eslint-plugin-storybook: 0.6.15 => 0.6.15 
    msw-storybook-addon: 2.0.0 => 2.0.0 
    storybook: 8.0.8 => 8.0.8 
    storybook-addon-pseudo-states: 3.0.1 => 3.0.1 
    storybook-addon-remix-react-router: 3.0.0 => 3.0.0 


### Additional context

_No response_
@jacobleetodd
Copy link
Author

@kasperpeulen thanks!

@kasperpeulen kasperpeulen self-assigned this Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Empathy Backlog
Development

No branches or pull requests

2 participants