You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When testing which arguments were given to a storybook action, I use the code given below. However, there are many situations where I do not want to make an exact comparison. For example, list ordering and object IDs.
import{expect}from'@storybook/jest';import{within,userEvent,}from'@storybook/testing-library';exportconstDemo={render: (args)=>(<buttontype="button"onClick={()=>args.onSubmit('John',25)}>Click</button>),argTypes: {onSubmit: {action: true},},play: async({ args, canvasElement })=>{awaituserEvent.click(within(canvasElement).getByRole('button'));awaitexpect(args.onSubmit).toHaveBeenCalledWith(expect.stringMatching(/([A-Z])\w+/gi),expect.anything(),);// or get the args directly insteadawaituserEvent.click(within(canvasElement).getByRole('button'));const[name,age]=args.onSubmit.mock.calls[0];awaitexpect(name).toEqual('John');awaitexpect(age).toEqual(25);}};
When testing which arguments were given to a storybook action, I use the code given below. However, there are many situations where I do not want to make an exact comparison. For example, list ordering and object IDs.
expect(args.onSubmit).toHaveBeenLastCalledWith(param1, param2);
How can I capture the arguments given to a storybook action into a variable? I can then compare against only parts of that variables, or as I wish.
The text was updated successfully, but these errors were encountered: