jeudi 11 juin 2020

Jest - mocking with 'mock' prefix not working

I want to mock a function of some module, but even after reading here https://github.com/facebook/jest/issues/9730#issuecomment-606512664, i'm still getting errors:

the code:

const mockGetPermissions = {getPermissions: jest.fn()}
jest.mock('./MyModule', () => mockGetPermissions)

the console:

The module factory of `jest.mock()` is not allowed to reference any out-of-scope variables.
    Invalid variable access: _get__
    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, console, expect, isNaN, jest, parseFloat, parseInt, require, undefined, globalThis, BigUint64Array, BigInt64Array, BigInt, decodeURI, decodeURIComponent, encodeURI, encodeURIComponent, escape, unescape, eval, isFinite, SharedArrayBuffer, Atomics, WebAssembly, global, process, GLOBAL, root, Buffer, URL, URLSearchParams, TextEncoder, TextDecoder, clearInterval, clearTimeout, setInterval, setTimeout, queueMicrotask, clearImmediate, setImmediate, __core-js_shared__.
    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` (case insensitive) are permitted.

But i'm putting the 'mock' prefix..Why it's not working?

Aucun commentaire:

Enregistrer un commentaire