jest-expo
TypeScript icon, indicating that this package has built-in type declarations

52.0.6 • Public • Published

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

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
52.0.6259,820latest
51.0.24,499sdk-51
53.0.0-preview.32,127next
50.0.3212sdk-50
53.0.0-canary-20250408-7f0ab5365canary

Version History

VersionDownloads (Last 7 Days)Published
53.0.0-preview.32,127
53.0.0-preview.21,180
53.0.0-preview.146
53.0.0-canary-20250408-7f0ab5365
53.0.0-canary-20250407-10a9b42106
53.0.0-preview.0197
53.0.0-canary-20250404-3c3b5fd6
53.0.0-canary-20250404-87e250622
53.0.0-canary-20250404-42b62636
53.0.0-canary-20250403-13261ac5
53.0.0-canary-20250402-161f57b4
53.0.0-canary-20250331-817737a6
53.0.0-canary-20250320-7a205d35
52.0.6259,820
53.0.0-canary-20250306-d9d3e0220
53.0.0-canary-20250305-0af9ad22
53.0.0-canary-20250304-f08e98435
53.0.0-canary-20250304-8a21aa71
53.0.0-canary-20250304-0da39713
53.0.0-canary-20250303-4dba60e3
52.0.519,598
53.0.0-canary-20250221-ef26fed0
53.0.0-canary-20250219-4a5dade0
52.0.415,600
53.0.0-canary-20250207-8bc51460
53.0.0-canary-20250131-5c4e5881
53.0.0-canary-20250124-42fe3321
53.0.0-canary-20250122-166c2cb0
53.0.0-canary-20250114-804e26d0
52.0.357,101
53.0.0-canary-20241211-61c49bd0
52.0.225,392
52.0.1260
52.0.0720
52.0.0-preview.41
52.0.0-preview.38
52.0.0-preview.20
52.0.0-preview.10
52.0.0-preview.00
52.0.0-canary-20241021-c4b5a934
52.0.0-canary-20241021-7aba8131
52.0.0-canary-20241018-ebd377a1
52.0.0-canary-20241018-2a482e31
52.0.0-canary-20241018-75a0b252
52.0.0-canary-20241018-4f8243a1
52.0.0-canary-20241018-f71b3e00
52.0.0-canary-20241018-bf4b2f7-10
52.0.0-canary-20241018-bf4b2f70
52.0.0-canary-20241008-90b13ad0
52.0.0-canary-20240927-ab8a9620
52.0.0-canary-20240912-1059f851
52.0.0-canary-20240904-69100c10
51.0.4147,564
52.0.0-canary-20240814-ce0f7d52
52.0.0-canary-20240719-83ee47b1
52.0.0-canary-20240628-1ba81521
52.0.0-canary-20240627-1402f4b1
52.0.0-canary-20240625-2333e701
51.0.39,422
51.0.24,499
51.0.11,356
51.0.082
51.0.0-canary-20240418-8d745970
51.0.0-canary-20240415-cca04d81
51.0.0-canary-20240415-0868fc41
51.0.0-canary-20240411-55a00850
51.0.0-canary-20240411-33a7dc10
51.0.0-canary-20240406-a4950c70
51.0.0-canary-20240405-cdfd9c10
51.0.0-canary-20240404-e2b87430
51.0.0-canary-20240328-24ecc5e0
51.0.0-canary-20240327-a7302d90
51.0.0-canary-20240320-8a10e090
51.0.0-canary-20240318-dd8f2450
51.0.0-canary-20240318-af634b10
51.0.0-canary-20240318-53194f50
51.0.0-canary-20240315-ce710050
50.0.422,187
50.0.0-canary-20240308-67158750
50.0.3212
50.0.0-canary-20240305-e60019e0
50.0.0-canary-20240228-7cee6190
50.0.0-canary-20240222-c729a130
50.0.2663
50.0.0-canary-20240109-93608d80
50.0.13,127
50.0.060
50.0.0-canary-20231205-250b31f10
50.0.0-canary-20231130-c8a9bf90
50.0.0-canary-20231130-ede75a72
50.0.0-canary-20231129-c0ec0230
50.0.0-canary-20231125-d600e4447
50.0.0-canary-20231123-1b19f960
50.0.0-alpha.4147
50.0.0-alpha.391
50.0.0-alpha.2601
50.0.0-alpha.16
50.0.0-alpha.00
49.0.012,853
49.0.0-alpha.50
49.0.0-alpha.40
49.0.0-alpha.30
49.0.0-alpha.20
49.0.0-alpha.11
48.0.27,058
48.0.189
48.0.077
47.0.12,017
47.0.021
46.0.21,308
46.0.1877
46.0.01
45.0.1319
45.0.045
45.0.0-beta.20
45.0.0-beta.10
44.0.1683
44.0.00
44.0.0-beta.00
43.0.1587
43.0.01
43.0.0-beta.11
43.0.0-beta.00
42.1.0147
42.0.156
42.0.033
41.0.0438
41.0.0-beta.01
41.0.0-alpha.00
40.0.2277
40.0.184
40.0.01
40.0.0-beta.10
40.0.0-beta.00
39.0.0240
38.0.217
38.0.10
38.0.00
37.0.02,670
36.0.171
36.0.01
36.0.0-rc.01
35.0.052
35.0.0-rc.00
34.1.04
34.0.17
34.0.01
34.0.0-rc.00
33.0.2157
33.0.10
33.0.01
33.0.0-rc.10
33.0.0-rc.00
32.0.162
32.0.010
32.0.0-rc.31
32.0.0-rc.20
32.0.0-rc.10
32.0.0-rc.01
31.0.08
31.0.0-rc.10
31.0.0-rc.00
30.0.03
30.0.0-rc.00
29.0.015
29.0.0-rc.30
29.0.0-rc.21
29.0.0-rc.10
29.0.0-rc.00
28.0.07
28.0.0-rc.01
27.0.155
27.0.01
27.0.0-rc.00
26.0.010
26.0.0-alpha.10
26.0.0-alpha.00
25.1.05
25.1.0-beta.00
25.0.03
25.0.0-rc.20
25.0.0-rc.11
25.0.0-rc.00
24.0.06
23.0.12
23.0.04
23.0.0-rc.00
22.0.1-SNAPSHOT.2017.11.11
22.0.1-SNAPSHOT.2017.10.310
22.0.1-snapshot.2017.10.291
22.0.13
22.0.01
22.0.0-alpha.00
21.0.2-SNAPSHOT.d993f41d0
21.0.2-SNAPSHOT.dfc397530
21.0.223
21.0.10
21.0.00
20.0.01
20.0.0-rc.10
20.0.0-rc.00
19.0.53
19.0.40
19.0.30
19.0.23
19.0.2-rc.10
19.0.2-rc.00
19.0.11
19.0.00
19.0.0-rc.10
19.0.0-rc.01
18.0.00
18.0.0-rc.10
18.0.0-rc.00
1.0.32
1.0.20
1.0.10
1.0.1-rc.10
1.0.01
0.4.01
0.4.0-alpha.10
0.4.0-alpha.00
0.3.10
0.3.00
0.2.30
0.2.21
0.2.12
0.3.0-beta.01

Package Sidebar

Install

npm i jest-expo

Weekly Downloads

602,875

Version

52.0.6

License

MIT

Unpacked Size

116 kB

Total Files

38

Last publish

Collaborators

  • tsapeta
  • ide
  • lukmccall
  • pkham
  • radoslawkrzemien
  • fiber-god
  • betoatexpo
  • brentvatne
  • evanbacon
  • quinlanj
  • expoadmin
  • exponent
  • wschurman
  • bycedric
  • jonsamp
  • princefleaswallow
  • kudochien
  • keith-kurak
  • alanhughes
  • simek
  • gabrieldonadel
  • douglowder
  • kadikraman
  • aleqsio
  • expo-bot
  • philpl
  • marklawlor