diff --git a/code/addons/interactions/src/components/Interaction.tsx b/code/addons/interactions/src/components/Interaction.tsx index c5e5e41f3d5e..b50e1a8382a7 100644 --- a/code/addons/interactions/src/components/Interaction.tsx +++ b/code/addons/interactions/src/components/Interaction.tsx @@ -5,12 +5,12 @@ import { styled, typography } from '@storybook/theming'; import { transparentize } from 'polished'; import { ListUnorderedIcon } from '@storybook/icons'; -import { Expected, MatcherResult, Received } from './MatcherResult'; +import { MatcherResult } from './MatcherResult'; import { MethodCall } from './MethodCall'; import { StatusIcon } from './StatusIcon'; import type { Controls } from './InteractionsPanel'; -import { isJestError } from '../utils'; +import { isChaiError, isJestError } from '../utils'; const MethodCallWrapper = styled.div(() => ({ fontFamily: typography.fonts.mono, @@ -117,33 +117,23 @@ export const Exception = ({ exception }: { exception: Call['exception'] }) => { if (isJestError(exception)) { return ; } + if (isChaiError(exception)) { + return ( + + +

See the full stack trace in the browser console.

+
+ ); + } + const paragraphs = exception.message.split('\n\n'); const more = paragraphs.length > 1; return (
{paragraphs[0]}
- {exception.showDiff && exception.diff ? ( - <> -
- - - ) : ( -
-          
- {exception.expected && ( - <> - Expected: -
- - )} - {exception.actual && ( - <> - Received: -
- - )} -
- )} {more &&

See the full stack trace in the browser console.

}
); diff --git a/code/addons/interactions/src/components/InteractionsPanel.stories.tsx b/code/addons/interactions/src/components/InteractionsPanel.stories.tsx index 5f8dd331935b..65d16a1b68a6 100644 --- a/code/addons/interactions/src/components/InteractionsPanel.stories.tsx +++ b/code/addons/interactions/src/components/InteractionsPanel.stories.tsx @@ -120,11 +120,11 @@ export const Failed: Story = { }, }; -export const NoInteractions: Story = { - args: { - interactions: [], - }, -}; +// export const NoInteractions: Story = { +// args: { +// interactions: [], +// }, +// }; export const CaughtException: Story = { args: { diff --git a/code/addons/interactions/src/components/MatcherResult.stories.tsx b/code/addons/interactions/src/components/MatcherResult.stories.tsx index c81ac36eb201..4ac31a71ecdb 100644 --- a/code/addons/interactions/src/components/MatcherResult.stories.tsx +++ b/code/addons/interactions/src/components/MatcherResult.stories.tsx @@ -29,11 +29,18 @@ export default { export const Expected = { args: { message: dedent` - expect(jest.fn()).lastCalledWith(...expected) - - Expected: {"email": "michael@chromatic.com", "password": "testpasswordthatwontfail"} - - Number of calls: 0 + expected last "spy" call to have been called with [ { …(2) } ] + + - Expected: + Array [ + Object { + "email": "michael@chromatic.com", + "password": "testpasswordthatwontfail", + }, + ] + + + Received: + undefined `, }, }; @@ -41,12 +48,18 @@ export const Expected = { export const ExpectedReceived = { args: { message: dedent` - expect(jest.fn()).toHaveBeenCalledWith(...expected) - - Expected: called with 0 arguments - Received: {"email": "michael@chromatic.com", "password": "testpasswordthatwontfail"} - - Number of calls: 1 + expected last "spy" call to have been called with [] + + - Expected + + Received + + - Array [] + + Array [ + + Object { + + "email": "michael@chromatic.com", + + "password": "testpasswordthatwontfail", + + }, + + ] `, }, }; @@ -54,10 +67,21 @@ export const ExpectedReceived = { export const ExpectedNumberOfCalls = { args: { message: dedent` - expect(jest.fn()).toHaveBeenCalledTimes(expected) - - Expected number of calls: 1 - Received number of calls: 0 + expected "spy" to not be called at all, but actually been called 1 times + + Received: + + 1st spy call: + + Array [ + Object { + "email": "michael@chromatic.com", + "password": "testpasswordthatwontfail", + }, + ] + + + Number of calls: 1 `, }, }; @@ -65,17 +89,21 @@ export const ExpectedNumberOfCalls = { export const Diff = { args: { message: dedent` - expect(jest.fn()).toHaveBeenCalledWith(...expected) - - - Expected - + Received - - Object { - - "email": "michael@chromatic.com", - + "email": "michael@chromaui.com", - "password": "testpasswordthatwontfail", - }, - + expected "spy" to be called with arguments: [ { …(2) } ] + + Received: + + 1st spy call: + + Array [ + Object { + - "email": "michael@chromaui.com", + + "email": "michael@chromatic.com", + "password": "testpasswordthatwontfail", + }, + ] + + Number of calls: 1 `, }, diff --git a/code/addons/interactions/src/components/MatcherResult.tsx b/code/addons/interactions/src/components/MatcherResult.tsx index ec75109a0598..fdd1fbdc4b83 100644 --- a/code/addons/interactions/src/components/MatcherResult.tsx +++ b/code/addons/interactions/src/components/MatcherResult.tsx @@ -85,7 +85,7 @@ export const MatcherResult = ({ if (line.match(/^\s*- /)) { return [,
]; } - if (line.match(/^\s*\+ /)) { + if (line.match(/^\s*\+ /) || line.match(/^Received: $/)) { return [,
]; } diff --git a/code/ui/.storybook/main.ts b/code/ui/.storybook/main.ts index 03dea1aea08d..72ec5445cb60 100644 --- a/code/ui/.storybook/main.ts +++ b/code/ui/.storybook/main.ts @@ -30,6 +30,10 @@ const allStories = [ directory: '../../addons/onboarding/src', titlePrefix: '@addons/onboarding', }, + { + directory: '../../addons/interactions/src', + titlePrefix: '@addons/interactions', + }, ]; /**