jest-expo
A Jest preset to painlessly test your Expo / React Native apps.
Last updated 9 months ago by wschurman .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install jest-expo 
SYNC missed versions from official npm registry.

jest-expo

A Jest preset to painlessly test your Expo / React Native apps.

Installation

  • To install the compatible version of jest-expo and jest for your project, run: npx expo install jest-expo jest.

  • Add the following config to package.json:

    "scripts": {
      ...
      "test": "jest"
    },
    "jest": {
      "preset": "jest-expo"
    }
    
  • Create a __tests__ directory anywhere you like and a Example-test.js file inside of it, and add this code:

    it('works', () => {
      expect(1).toBe(1);
    });
    
  • Run npm test and it should pass

You can use a different version of jest than the one that is installed with expo install, but keep in mind that the SDK and jest-expo are built against that version.

Platforms

You can use jest-expo to test any Expo supported platform. For legacy purposes jest-expo runs your tests in the standard React Native environment (iOS). The recommended way to test your project is with jest-expo/universal which runs your tests with every Expo supported platform. Currently this includes iOS, Android, web, and Node (which is used for testing SSR compliance).

Pressing X will open a platform-selection dialog that you can use to test individual platforms. You can also create a custom Jest config and combine the individual platforms with jest-expo/ios, jest-expo/android, jest-expo/web, and jest-expo/node.

Snapshots

Because a test is run with multiple different platforms, jest-expo saves snapshots using the name of the platform as the extension. This is very useful for testing something like view styles, which are computed differently across web and native.

Here is an example output:

|- View-test.tsx |-- __snapshots__/View-test.tsx.snap.android |-- __snapshots__/View-test.tsx.snap.ios |-- __snapshots__/View-test.tsx.snap.node |-- __snapshots__/View-test.tsx.snap.web

Extensions

To test specific platforms you can use the following extensions:

  • iOS: -test.ios.*, -test.native.*
  • Android: -test.android.*, -test.native.*
  • web: -test.web.*
  • Node: -test.node.*, -test.web.*

Mixing runners

If you don't want to use every runner you can always mix runners by using the projects field of your Jest config. This will only work with single-runner projects like jest-expo/ios, jest-expo/android, jest-expo/web, and jest-expo/node.

"jest": {
-  "preset": "jest-expo/universal"
// Skip web and Node tests
+ "projects": [
+    { "preset": "jest-expo/ios" },
+    { "preset": "jest-expo/android"}
+ ]
},

Testing JSX Components

To test the output of your React components you can use the library jest-expo-enzyme, which extends jest-expo and adds universal Enzyme support.

⚙️ Configuring your preset

When building a custom preset you may want to use some of features provided by this preset. You can access these features through the jest-expo/config directory.

getWatchPlugins(jestConfig)

When given an existing Jest config this will return the watchPlugins used in jest-expo. This reads the projects field to determine which watchPlugins to return for single-project and multi-project configs.

Currently this returns type-ahead plugins for all projects:

  • jest-watch-typeahead/filename
  • jest-watch-typeahead/testname

And a custom platform selection dialog for universal multi-projects:

  • jest-watch-select-projects

withWatchPlugins(jestConfig)

Given a Jest config, this will ensure any existing watchPlugins are safely merged with getWatchPlugins(jestConfig).

getWebPreset()

Alternative to jest-expo/web. This runs in a JSDOM environment for testing Expo web.

getIOSPreset()

Alternative to jest-expo/ios. Runs in a mock native environment.

getAndroidPreset()

Alternative to jest-expo/android. Also runs in a mock native environment.

getNodePreset()

Alternative to jest-expo/node. This runs in a Node environment for testing SSR.

Learning Jest

Read the Jest documentation

Current Tags

  • 52.0.0-canary-20240904-69100c1                                ...           canary (2 months ago)
  • 51.0.4                                ...           latest (3 months ago)
  • 51.0.4                                ...           next (3 months ago)
  • 50.0.3                                ...           sdk-50 (8 months ago)
  • 51.0.2                                ...           sdk-51 (6 months ago)

177 Versions

  • 52.0.0-canary-20240904-69100c1                                ...           2 months ago
  • 51.0.4                                ...           3 months ago
  • 52.0.0-canary-20240814-ce0f7d5                                ...           3 months ago
  • 52.0.0-canary-20240719-83ee47b                                ...           4 months ago
  • 52.0.0-canary-20240628-1ba8152                                ...           5 months ago
  • 52.0.0-canary-20240627-1402f4b                                ...           5 months ago
  • 52.0.0-canary-20240625-2333e70                                ...           5 months ago
  • 51.0.3                                ...           5 months ago
  • 51.0.2                                ...           6 months ago
  • 51.0.1                                ...           7 months ago
  • 51.0.0                                ...           7 months ago
  • 51.0.0-canary-20240418-8d74597                                ...           7 months ago
  • 51.0.0-canary-20240415-cca04d8                                ...           7 months ago
  • 51.0.0-canary-20240415-0868fc4                                ...           7 months ago
  • 51.0.0-canary-20240411-55a0085                                ...           7 months ago
  • 51.0.0-canary-20240411-33a7dc1                                ...           7 months ago
  • 51.0.0-canary-20240406-a4950c7                                ...           7 months ago
  • 51.0.0-canary-20240405-cdfd9c1                                ...           7 months ago
  • 51.0.0-canary-20240404-e2b8743                                ...           7 months ago
  • 51.0.0-canary-20240328-24ecc5e                                ...           8 months ago
  • 51.0.0-canary-20240327-a7302d9                                ...           8 months ago
  • 51.0.0-canary-20240320-8a10e09                                ...           8 months ago
  • 51.0.0-canary-20240318-dd8f245                                ...           8 months ago
  • 51.0.0-canary-20240318-af634b1                                ...           8 months ago
  • 51.0.0-canary-20240318-53194f5                                ...           8 months ago
  • 51.0.0-canary-20240315-ce71005                                ...           8 months ago
  • 50.0.4                                ...           8 months ago
  • 50.0.0-canary-20240308-6715875                                ...           8 months ago
  • 50.0.3                                ...           8 months ago
  • 50.0.0-canary-20240305-e60019e                                ...           8 months ago
  • 50.0.0-canary-20240228-7cee619                                ...           9 months ago
  • 50.0.0-canary-20240222-c729a13                                ...           9 months ago
  • 50.0.2                                ...           9 months ago
  • 50.0.0-canary-20240109-93608d8                                ...           10 months ago
  • 50.0.1                                ...           a year ago
  • 50.0.0                                ...           a year ago
  • 50.0.0-canary-20231205-250b31f                                ...           a year ago
  • 50.0.0-canary-20231130-c8a9bf9                                ...           a year ago
  • 50.0.0-canary-20231130-ede75a7                                ...           a year ago
  • 50.0.0-canary-20231129-c0ec023                                ...           a year ago
  • 50.0.0-canary-20231125-d600e44                                ...           a year ago
  • 50.0.0-canary-20231123-1b19f96                                ...           a year ago
  • 50.0.0-alpha.4                                ...           a year ago
  • 50.0.0-alpha.3                                ...           a year ago
  • 50.0.0-alpha.2                                ...           a year ago
  • 50.0.0-alpha.1                                ...           a year ago
  • 50.0.0-alpha.0                                ...           a year ago
  • 49.0.0                                ...           a year ago
  • 49.0.0-alpha.5                                ...           a year ago
  • 49.0.0-alpha.4                                ...           a year ago
  • 49.0.0-alpha.3                                ...           a year ago
  • 49.0.0-alpha.2                                ...           a year ago
  • 49.0.0-alpha.1                                ...           2 years ago
  • 48.0.2                                ...           2 years ago
  • 48.0.1                                ...           2 years ago
  • 48.0.0                                ...           2 years ago
  • 47.0.1                                ...           2 years ago
  • 47.0.0                                ...           2 years ago
  • 46.0.2                                ...           2 years ago
  • 46.0.1                                ...           2 years ago
  • 46.0.0                                ...           2 years ago
  • 45.0.1                                ...           3 years ago
  • 45.0.0                                ...           3 years ago
  • 45.0.0-beta.2                                ...           3 years ago
  • 45.0.0-beta.1                                ...           3 years ago
  • 44.0.1                                ...           3 years ago
  • 44.0.0                                ...           3 years ago
  • 44.0.0-beta.0                                ...           3 years ago
  • 43.0.1                                ...           3 years ago
  • 43.0.0                                ...           3 years ago
  • 43.0.0-beta.1                                ...           3 years ago
  • 43.0.0-beta.0                                ...           3 years ago
  • 42.1.0                                ...           3 years ago
  • 42.0.1                                ...           3 years ago
  • 42.0.0                                ...           3 years ago
  • 41.0.0                                ...           4 years ago
  • 41.0.0-beta.0                                ...           4 years ago
  • 41.0.0-alpha.0                                ...           4 years ago
  • 40.0.2                                ...           4 years ago
  • 40.0.1                                ...           4 years ago
  • 40.0.0                                ...           4 years ago
  • 40.0.0-beta.1                                ...           4 years ago
  • 40.0.0-beta.0                                ...           4 years ago
  • 39.0.0                                ...           4 years ago
  • 38.0.2                                ...           4 years ago
  • 38.0.1                                ...           4 years ago
  • 38.0.0                                ...           4 years ago
  • 37.0.0                                ...           5 years ago
  • 36.0.1                                ...           5 years ago
  • 36.0.0                                ...           5 years ago
  • 36.0.0-rc.0                                ...           5 years ago
  • 35.0.0                                ...           5 years ago
  • 35.0.0-rc.0                                ...           5 years ago
  • 34.1.0                                ...           5 years ago
  • 34.0.1                                ...           5 years ago
  • 34.0.0                                ...           5 years ago
  • 34.0.0-rc.0                                ...           5 years ago
  • 33.0.2                                ...           5 years ago
  • 33.0.1                                ...           5 years ago
  • 33.0.0                                ...           5 years ago
  • 33.0.0-rc.1                                ...           5 years ago
  • 33.0.0-rc.0                                ...           5 years ago
  • 32.0.1                                ...           5 years ago
  • 32.0.0                                ...           6 years ago
  • 32.0.0-rc.3                                ...           6 years ago
  • 32.0.0-rc.2                                ...           6 years ago
  • 32.0.0-rc.1                                ...           6 years ago
  • 32.0.0-rc.0                                ...           6 years ago
  • 31.0.0                                ...           6 years ago
  • 31.0.0-rc.1                                ...           6 years ago
  • 31.0.0-rc.0                                ...           6 years ago
  • 30.0.0                                ...           6 years ago
  • 30.0.0-rc.0                                ...           6 years ago
  • 29.0.0                                ...           6 years ago
  • 29.0.0-rc.3                                ...           6 years ago
  • 29.0.0-rc.2                                ...           6 years ago
  • 29.0.0-rc.1                                ...           6 years ago
  • 29.0.0-rc.0                                ...           6 years ago
  • 28.0.0                                ...           6 years ago
  • 28.0.0-rc.0                                ...           6 years ago
  • 27.0.1                                ...           7 years ago
  • 27.0.0                                ...           7 years ago
  • 27.0.0-rc.0                                ...           7 years ago
  • 26.0.0                                ...           7 years ago
  • 26.0.0-alpha.1                                ...           7 years ago
  • 26.0.0-alpha.0                                ...           7 years ago
  • 25.1.0                                ...           7 years ago
  • 25.1.0-beta.0                                ...           7 years ago
  • 25.0.0                                ...           7 years ago
  • 25.0.0-rc.2                                ...           7 years ago
  • 25.0.0-rc.1                                ...           7 years ago
  • 25.0.0-rc.0                                ...           7 years ago
  • 24.0.0                                ...           7 years ago
  • 23.0.1                                ...           7 years ago
  • 23.0.0                                ...           7 years ago
  • 23.0.0-rc.0                                ...           7 years ago
  • 22.0.1-SNAPSHOT.2017.11.1                                ...           7 years ago
  • 22.0.1-SNAPSHOT.2017.10.31                                ...           7 years ago
  • 22.0.1-snapshot.2017.10.29                                ...           7 years ago
  • 22.0.1                                ...           7 years ago
  • 22.0.0                                ...           7 years ago
  • 22.0.0-alpha.0                                ...           7 years ago
  • 21.0.2-SNAPSHOT.d993f41d                                ...           7 years ago
  • 21.0.2-SNAPSHOT.dfc39753                                ...           7 years ago
  • 21.0.2                                ...           7 years ago
  • 21.0.1                                ...           7 years ago
  • 21.0.0                                ...           7 years ago
  • 20.0.0                                ...           7 years ago
  • 20.0.0-rc.1                                ...           7 years ago
  • 20.0.0-rc.0                                ...           7 years ago
  • 19.0.5                                ...           7 years ago
  • 19.0.4                                ...           7 years ago
  • 19.0.3                                ...           7 years ago
  • 19.0.2                                ...           7 years ago
  • 19.0.2-rc.1                                ...           7 years ago
  • 19.0.2-rc.0                                ...           7 years ago
  • 19.0.1                                ...           7 years ago
  • 19.0.0                                ...           7 years ago
  • 19.0.0-rc.1                                ...           7 years ago
  • 19.0.0-rc.0                                ...           7 years ago
  • 18.0.0                                ...           7 years ago
  • 18.0.0-rc.1                                ...           7 years ago
  • 18.0.0-rc.0                                ...           7 years ago
  • 1.0.3                                ...           7 years ago
  • 1.0.2                                ...           7 years ago
  • 1.0.1                                ...           7 years ago
  • 1.0.1-rc.1                                ...           7 years ago
  • 1.0.0                                ...           7 years ago
  • 0.4.0                                ...           8 years ago
  • 0.4.0-alpha.1                                ...           8 years ago
  • 0.4.0-alpha.0                                ...           8 years ago
  • 0.3.1                                ...           8 years ago
  • 0.3.0                                ...           8 years ago
  • 0.2.3                                ...           8 years ago
  • 0.2.2                                ...           8 years ago
  • 0.2.1                                ...           8 years ago
  • 0.3.0-beta.0                                ...           8 years ago

© 2010 - cnpmjs.org x YWFE | Home | YWFE