Skip to content

Commit 194d112

Browse files
BboyAkersljharb
authored andcommitted
Added file path and in/at ternary to error test
1 parent ac84739 commit 194d112

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

packages/enzyme-test-suite/test/shared/lifecycles/componentDidCatch.jsx

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -251,18 +251,23 @@ export default function describeCDC({
251251
if (is('>= 17')) {
252252
expect(info).to.have.property('componentStack');
253253
expect(info.componentStack).to.match(/at Thrower (.+)\n/);
254-
} else {
255-
expect(info).to.deep.equal({
256-
componentStack: `
257-
in Thrower (created by ErrorBoundary)
258-
in span (created by ErrorBoundary)${hasFragments ? '' : `
259-
in main (created by ErrorBoundary)`}
260-
in div (created by ErrorBoundary)
261-
in ErrorBoundary (created by ErrorSFC)
262-
in ErrorSFC (created by WrapperComponent)
263-
in WrapperComponent`,
264-
});
265-
}
254+
}
255+
// else {
256+
var FILE_PATH = __filename.replace(/^.*?(\/build)/, '$1');
257+
var inStr = is('>= 17') ? 'at' : 'in';
258+
info.componentStack = info.componentStack.replace(/^.*?(\/build)/, '$1');
259+
info.componentStack = info.componentStack.replace(/at/g, inStr);
260+
expect(info).to.deep.equal({
261+
componentStack: `
262+
${inStr} Thrower (${FILE_PATH})
263+
${inStr} span (${FILE_PATH})${hasFragments ? '' : `
264+
in main (${FILE_PATH})`}
265+
${inStr} div (${FILE_PATH})
266+
${inStr} ErrorBoundary (created by ErrorSFC)
267+
${inStr} ErrorSFC (created by WrapperComponent)
268+
${inStr} WrapperComponent`,
269+
});
270+
// }
266271
});
267272
});
268273
});

0 commit comments

Comments
 (0)