Passing out-of-scope variable with jest.mock

后端 未结 1 1381
北恋
北恋 2021-02-07 08:53

I have a mock object that I am using to mock react-native:

const MyMock = {
    MockA: {
        methodA: jest.genMockFn()
    },
    MockB: {
              


        
相关标签:
1条回答
  • 2021-02-07 09:28

    I hadn't read the error message fully. On the last line(slightly obscured) there is this:

    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.

    So when I changed MyMock to for instance mockMyMock, it worked.

    0 讨论(0)
提交回复
热议问题