on-internet
← Community

jest ReferenceError: Cannot access '' before initialization

Stack Overflow ·

I'm getting the error: ReferenceError: Cannot access 'myMock' before initialization Even though i respected jest documentation about the hoisting: A limitation with the factory parameter is that, since calls to jest.mock() are hoisted to the top of the file, it's not possible to first define a variable and then use it in the factory. An exception is made for variables that start with the word 'mock'. I'm doing this: import MyClass from './my_class'; import * as anotherClass from './another_class'; const mockMethod1 = jest.fn(); const mockMethod2 = jest.fn(); jest.mock('./my_class', () => { ret

Comments

Sign in or sign up to comment and upvote.

No comments yet.