Back to Expo

Generating new Jest Mocks

guides/Generating Jest Mocks.md

latest1.7 KB
Original Source

Generating new Jest Mocks

This document will guide you through the process of generating new Jest Mocks for packages/jest-expo module using apps/jest-expo-mock-generator.

Why

We provide some mocks of our native methods which are generated by traversing all the modules and its methods and making a configuration of all those methods with the number of arguments etc.

How

  1. In your terminal, go to apps/jest-expo-mock-generator
  • run yarn to ensure the dependencies are installed
  • run expo start to start the Expo server
  1. Open the Expo Go project on iOS by opening ios/Exponent.xcworkspace
  • run the project on a simulator or a device
  1. Open jest-expo-mock-generator in the running Expo Go app

  2. After the app is finished opening, in the terminal, where the Expo server is running, you should see a big chunk of text wrapped with

    ------------------------------COPY THE TEXT BELOW------------------------------

    and

    ------------------------------END OF TEXT TO COPY------------------------------

    lines. Select and copy the text from between those lines.

https://user-images.githubusercontent.com/379606/120577838-b4964a80-c3d9-11eb-93db-aba3ea9eef41.mp4

  1. Stop the Expo server running in apps/jest-expo-mock-generator, started in step 1.

  2. Paste the copied text into packages/jest-expo/src/preset/expoModules.js.

  3. In the terminal, go into packages/jest-expo.

  4. Run yarn prettier src/preset/expoModules.js --write.

  5. Commit the changes. Bonus points for not modifying mock values (like deviceYearClass), which will be different if you use a test device different than the one used before.