MCPcopy Create free account
hub / github.com/testing-library/react-testing-library / newMethod

Function newMethod

tests/failOnUnexpectedConsoleCalls.js:32–47  ·  view source on GitHub ↗
(format, ...args)

Source from the content-addressed store, hash-verified

30
31const patchConsoleMethod = (methodName, unexpectedConsoleCallStacks) => {
32 const newMethod = function (format, ...args) {
33 // Ignore uncaught errors reported by jsdom
34 // and React addendums because they're too noisy.
35 if (methodName === 'error' && shouldIgnoreConsoleError(format, args)) {
36 return
37 }
38
39 // Capture the call stack now so we can warn about it later.
40 // The call stack has helpful information for the test author.
41 // Don't throw yet though b'c it might be accidentally caught and suppressed.
42 const stack = new Error().stack
43 unexpectedConsoleCallStacks.push([
44 stack.substr(stack.indexOf('\n') + 1),
45 util.format(format, ...args),
46 ])
47 }
48
49 console[methodName] = newMethod
50

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…