Jest: The module factory of `jest.mock()` is not allowed to reference any out-of-scope variables.

Created on 10 Jul 2018  路  1Comment  路  Source: facebook/jest

Hi Team,

When I am trying to run the test case, Test suite always failed to run with below error:

node_modules/react-native/jest/setup.js: babel-plugin-jest-hoist: The module factory of jest.mock() is not allowed to reference any out-of-scope variables.

Invalid variable access: console
Whitelisted objects: Array, ArrayBuffer, Boolean, DataView, Date, Error, EvalError, Float32Array, Float64Array, Function, Generator, GeneratorFunction, Infinity, Int16Array, Int32Array, Int8Array, InternalError, Intl, JSON, Map, Math, NaN, Number, Object, Promise, Proxy, RangeError, ReferenceError, Reflect, RegExp, Set, String, Symbol, SyntaxError, TypeError, URIError, Uint16Array, Uint32Array, Uint8Array, Uint8ClampedArray, WeakMap, WeakSet, arguments, expect, jest, require, undefined, DTRACE_NET_SERVER_CONNECTION, DTRACE_NET_STREAM_END, DTRACE_HTTP_SERVER_REQUEST, DTRACE_HTTP_SERVER_RESPONSE, DTRACE_HTTP_CLIENT_REQUEST, DTRACE_HTTP_CLIENT_RESPONSE, global, process, Buffer, clearImmediate, clearInterval, clearTimeout, setImmediate, setInterval, setTimeout.
Note: This is a precaution to guard against uninitialized mock variables. If it is ensured that the mock is required lazily, variable names prefixed with `mock` are permitted.

Installed software version:
npm: 6.1.0
node: v10.6.0
react-native-cli: 2.0.1
react-native: 0.50.4

Error screenshot:
mock-error

>All comments

Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

Was this page helpful?
0 / 5 - 0 ratings