Skip to content

Commit 9dbe23c

Browse files
committed
Warn about spying on the console
1 parent faa4218 commit 9dbe23c

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

scripts/jest/setupTests.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,21 @@ if (process.env.REACT_CLASS_EQUIVALENCE_TEST) {
1313
// https://github.com/facebook/jest/blob/v20.0.4/packages/jest-matchers/src/spyMatchers.js#L160
1414
const isSpy = spy => spy.calls && typeof spy.calls.count === 'function';
1515

16-
const spyOn = global.spyOn;
16+
// This is the Jasmine spyOn() method.
17+
// Unlike jest.spyOn(), it does not pass through to the method it spies on by default.
18+
const jasmineSpyOn = global.spyOn;
19+
1720
const noop = function() {};
21+
const spyOn = function(object, methodName) {
22+
if (object === console) {
23+
throw new Error(
24+
'Do not spy on the console directly. ' +
25+
'Use toWarnDev() or toLowPriorityWarnDev() instead.'
26+
);
27+
}
28+
29+
jasmineSpyOn(object, methodName);
30+
};
1831

1932
// Spying on console methods in production builds can mask errors.
2033
// This is why we added an explicit spyOnDev() helper.

0 commit comments

Comments
 (0)