react-native-jest-mocks icon indicating copy to clipboard operation
react-native-jest-mocks copied to clipboard

babel-plugin-jest-hoist: The second argument of `jest.mock` must be an inline function.

Open mauriciord opened this issue 5 years ago • 4 comments

I'm using Expo, when I try to add this config, like you mentioned on README:

const mocks = require('react-native-jest-mocks');

mocks.initAll();
Screen Shot 2019-10-24 at 14 39 48
 Expo CLI 3.4.0 environment info:
    System:
      OS: macOS 10.15
      Shell: 5.7.1 - /bin/zsh
    Binaries:
      Node: 10.16.3 - ~/.nvm/versions/node/v10.16.3/bin/node
      Yarn: 1.19.1 - ~/.nvm/versions/node/v10.16.3/bin/yarn
      npm: 6.9.0 - ~/.nvm/versions/node/v10.16.3/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    IDEs:
      Android Studio: 3.1 AI-173.4720617
      Xcode: 11.0/11A420a - /usr/bin/xcodebuild
    npmPackages:
      @testing-library/react-native: ^4.0.7 => 4.0.7
      expo: ^35.0.0 => 35.0.0
      react: 16.8.3 => 16.8.3
      react-native: https://github.com/expo/react-native/archive/sdk-35.0.0.tar.gz => 0.59.8
      react-navigation: ^3.11.1 => 3.11.1
    npmGlobalPackages:
      expo-cli: 3.4.0

mauriciord avatar Oct 24 '19 20:10 mauriciord

@mauriciord thanks for reporting this! I'm gonna look into a fix for this issue. ✌️

Xabadu avatar Oct 26 '19 18:10 Xabadu

@Xabadu @mauriciord I narrowed this issue down to the react-native-localize section of mocks.js. Since I'm not using the localization library in my project I just commented it out and stopped digging, but I think it's similar to what's going on in this SO post: https://stackoverflow.com/questions/48159800/mocking-multiple-named-exports-in-jest-mockmodulename-factory-factory-functio

hope this helps and thanks for publishing your mocks!

zimke avatar Nov 18 '19 20:11 zimke

This bug affects my project too. With jest 25.1.0 and react-native-jest-mocks 1.5.0, I see this error:

TypeError: /project/path/node_modules/react-native-jest-mocks/src/mocks.js: The second argument of `jest.mock` must be an inline function.

  60 |     const removeEventListener = jest.fn();
  61 | 
> 62 |     jest.mock('findBestAvailableLanguage', findBestAvailableLanguage);

iamleeg avatar Feb 11 '20 10:02 iamleeg

The solution is to not use this module, but to add ./node_modules/react-native/jest/setup.js to my jest setupFiles.

iamleeg avatar Feb 26 '20 16:02 iamleeg