Skip to content

Commit 15a5e34

Browse files
authored
test: fix tests that use shouldWarn (react-bootstrap#5700)
1 parent 32fc702 commit 15a5e34

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

test/index.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,19 @@ beforeEach(() => {
2828
sinon.stub(console, 'error').callsFake((msg, ...args) => {
2929
let expected = false;
3030

31+
// When using the new JSX transform, React uses a different checkPropTypes
32+
// function that exists within react-jsx-dev-runtime.development.js that
33+
// sends in a string message with args. In contrast, without the JSX transform,
34+
// React (react.development.js) uses checkPropTypes from the prop-types package
35+
// and this formats the string prior to calling console.error.
36+
// We're going to need to format the string ourselves and check it.
37+
let formattedStr = msg;
38+
if (args.length) {
39+
formattedStr = Util.format(msg, ...args);
40+
}
41+
3142
console.error.expected.forEach((about) => {
32-
if (msg.indexOf(about) !== -1) {
43+
if (formattedStr.indexOf(about) !== -1) {
3344
console.error.warned[about] = true;
3445
expected = true;
3546
}
@@ -40,7 +51,7 @@ beforeEach(() => {
4051
}
4152

4253
console.error.threw = true;
43-
throw new Error(Util.format(msg, ...args));
54+
throw new Error(formattedStr);
4455
});
4556

4657
console.error.expected = [];

0 commit comments

Comments
 (0)