diff --git a/code/addons/test/src/components/Interaction.tsx b/code/addons/test/src/components/Interaction.tsx
index 4ceef384d02a..75797c65c5a3 100644
--- a/code/addons/test/src/components/Interaction.tsx
+++ b/code/addons/test/src/components/Interaction.tsx
@@ -23,7 +23,7 @@ const MethodCallWrapper = styled.div(() => ({
const RowContainer = styled('div', {
shouldForwardProp: (prop) => !['call', 'pausedAt'].includes(prop.toString()),
-})<{ call: Call; pausedAt: Call['id'] }>(
+})<{ call: Call; pausedAt: Call['id'] | undefined }>(
({ theme, call }) => ({
position: 'relative',
display: 'flex',
@@ -117,6 +117,9 @@ const RowMessage = styled('div')(({ theme }) => ({
export const Exception = ({ exception }: { exception: Call['exception'] }) => {
const filter = useAnsiToHtmlFilter();
+ if (!exception) {
+ return null;
+ }
if (isJestError(exception)) {
return ;
}
@@ -187,7 +190,7 @@ export const Interaction = ({
- {childCallIds?.length > 0 && (
+ {(childCallIds?.length ?? 0) > 0 && (
}
diff --git a/code/addons/test/src/components/MatcherResult.tsx b/code/addons/test/src/components/MatcherResult.tsx
index 46b5e540ad8d..fa01b73548ec 100644
--- a/code/addons/test/src/components/MatcherResult.tsx
+++ b/code/addons/test/src/components/MatcherResult.tsx
@@ -74,10 +74,10 @@ export const MatcherResult = ({
{lines.flatMap((line: string, index: number) => {
if (line.startsWith('expect(')) {
const received = getParams(line, 7);
- const remainderIndex = received && 7 + received.length;
+ const remainderIndex = received ? 7 + received.length : 0;
const matcher = received && line.slice(remainderIndex).match(/\.(to|last|nth)[A-Z]\w+\(/);
if (matcher) {
- const expectedIndex = remainderIndex + matcher.index + matcher[0].length;
+ const expectedIndex = remainderIndex + (matcher.index ?? 0) + matcher[0].length;
const expected = getParams(line, expectedIndex);
if (expected) {
return [
diff --git a/code/addons/test/src/components/MethodCall.tsx b/code/addons/test/src/components/MethodCall.tsx
index 59b907d13daa..34d1e6bb6f58 100644
--- a/code/addons/test/src/components/MethodCall.tsx
+++ b/code/addons/test/src/components/MethodCall.tsx
@@ -139,7 +139,7 @@ export const Node = ({
case Object.prototype.hasOwnProperty.call(value, '__class__'):
return ;
case Object.prototype.hasOwnProperty.call(value, '__callId__'):
- return ;
+ return ;
/* eslint-enable no-underscore-dangle */
case Object.prototype.toString.call(value) === '[object Object]':
@@ -418,7 +418,7 @@ export const MethodCall = ({
callsById,
}: {
call?: Call;
- callsById: Map;
+ callsById?: Map;
}) => {
// Call might be undefined during initial render, can be safely ignored.
if (!call) {
@@ -434,7 +434,7 @@ export const MethodCall = ({
const callId = (elem as CallRef).__callId__;
return [
callId ? (
-
+
) : (
{elem as any}
),
diff --git a/code/addons/test/src/components/Panel.tsx b/code/addons/test/src/components/Panel.tsx
index cc2eaf233356..d6ea74843151 100644
--- a/code/addons/test/src/components/Panel.tsx
+++ b/code/addons/test/src/components/Panel.tsx
@@ -22,14 +22,6 @@ import type { API_StatusValue } from '@storybook/types';
import { ADDON_ID, STORYBOOK_ADDON_TEST_CHANNEL, TEST_PROVIDER_ID } from '../constants';
import { InteractionsPanel } from './InteractionsPanel';
-interface Interaction extends Call {
- status: Call['status'];
- childCallIds: Call['id'][];
- isHidden: boolean;
- isCollapsed: boolean;
- toggleCollapsed: () => void;
-}
-
const INITIAL_CONTROL_STATES = {
start: false,
back: false,
@@ -60,7 +52,7 @@ export const getInteractions = ({
const childCallMap = new Map();
return log
- .map(({ callId, ancestors, status }) => {
+ .map(({ callId, ancestors, status }) => {
let isHidden = false;
ancestors.forEach((ancestor) => {
if (collapsed.has(ancestor)) {
@@ -68,11 +60,12 @@ export const getInteractions = ({
}
childCallMap.set(ancestor, (childCallMap.get(ancestor) || []).concat(callId));
});
- return { ...calls.get(callId), status, isHidden };
+ return { ...calls.get(callId)!, status, isHidden };
})
- .map((call) => {
+ .map((call) => {
const status =
call.status === CallStates.ERROR &&
+ call.ancestors &&
callsById.get(call.ancestors.slice(-1)[0])?.status === CallStates.ACTIVE
? CallStates.ACTIVE
: call.status;
@@ -131,7 +124,7 @@ export const Panel = memo<{ storyId: string }>(function PanelMemoized({ storyId
const calls = useRef