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

52.0.3 • 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.3125,232latest
51.0.26,780sdk-51
50.0.3585sdk-50
53.0.0-canary-20250131-5c4e5880canary

Version History

VersionDownloads (Last 7 Days)Published
53.0.0-canary-20250131-5c4e5880
53.0.0-canary-20250124-42fe33237
53.0.0-canary-20250122-166c2cb25
53.0.0-canary-20250114-804e26d5
52.0.3125,232
53.0.0-canary-20241211-61c49bd2
52.0.253,650
52.0.13,817
52.0.01,038
52.0.0-preview.45
52.0.0-preview.33
52.0.0-preview.21
52.0.0-preview.17
52.0.0-preview.00
52.0.0-canary-20241021-c4b5a932
52.0.0-canary-20241021-7aba8130
52.0.0-canary-20241018-ebd377a0
52.0.0-canary-20241018-2a482e30
52.0.0-canary-20241018-75a0b251
52.0.0-canary-20241018-4f8243a0
52.0.0-canary-20241018-f71b3e01
52.0.0-canary-20241018-bf4b2f7-10
52.0.0-canary-20241018-bf4b2f70
52.0.0-canary-20241008-90b13ad0
52.0.0-canary-20240927-ab8a9622
52.0.0-canary-20240912-1059f851
52.0.0-canary-20240904-69100c11
51.0.4113,286
52.0.0-canary-20240814-ce0f7d50
52.0.0-canary-20240719-83ee47b0
52.0.0-canary-20240628-1ba81523
52.0.0-canary-20240627-1402f4b1
52.0.0-canary-20240625-2333e702
51.0.321,775
51.0.26,780
51.0.12,086
51.0.071
51.0.0-canary-20240418-8d7459761
51.0.0-canary-20240415-cca04d80
51.0.0-canary-20240415-0868fc40
51.0.0-canary-20240411-55a00851
51.0.0-canary-20240411-33a7dc11
51.0.0-canary-20240406-a4950c70
51.0.0-canary-20240405-cdfd9c11
51.0.0-canary-20240404-e2b87430
51.0.0-canary-20240328-24ecc5e1
51.0.0-canary-20240327-a7302d91
51.0.0-canary-20240320-8a10e091
51.0.0-canary-20240318-dd8f2450
51.0.0-canary-20240318-af634b12
51.0.0-canary-20240318-53194f51
51.0.0-canary-20240315-ce710053
50.0.423,908
50.0.0-canary-20240308-67158752
50.0.3585
50.0.0-canary-20240305-e60019e2
50.0.0-canary-20240228-7cee6192
50.0.0-canary-20240222-c729a133
50.0.2747
50.0.0-canary-20240109-93608d81
50.0.11,053
50.0.098
50.0.0-canary-20231205-250b31f22
50.0.0-canary-20231130-c8a9bf90
50.0.0-canary-20231130-ede75a71
50.0.0-canary-20231129-c0ec0234
50.0.0-canary-20231125-d600e440
50.0.0-canary-20231123-1b19f960
50.0.0-alpha.461
50.0.0-alpha.3141
50.0.0-alpha.286
50.0.0-alpha.114
50.0.0-alpha.00
49.0.012,116
49.0.0-alpha.50
49.0.0-alpha.40
49.0.0-alpha.30
49.0.0-alpha.21
49.0.0-alpha.10
48.0.29,595
48.0.147
48.0.064
47.0.12,557
47.0.042
46.0.21,799
46.0.1398
46.0.02
45.0.1313
45.0.047
45.0.0-beta.20
45.0.0-beta.10
44.0.1492
44.0.02
44.0.0-beta.00
43.0.1138
43.0.01
43.0.0-beta.10
43.0.0-beta.00
42.1.0147
42.0.148
42.0.00
41.0.0273
41.0.0-beta.00
41.0.0-alpha.01
40.0.2331
40.0.158
40.0.00
40.0.0-beta.11
40.0.0-beta.00
39.0.029
38.0.248
38.0.10
38.0.00
37.0.03,487
36.0.166
36.0.00
36.0.0-rc.00
35.0.034
35.0.0-rc.01
34.1.06
34.0.119
34.0.00
34.0.0-rc.00
33.0.212
33.0.10
33.0.00
33.0.0-rc.11
33.0.0-rc.00
32.0.139
32.0.022
32.0.0-rc.30
32.0.0-rc.21
32.0.0-rc.11
32.0.0-rc.00
31.0.04
31.0.0-rc.10
31.0.0-rc.00
30.0.00
30.0.0-rc.00
29.0.017
29.0.0-rc.31
29.0.0-rc.20
29.0.0-rc.10
29.0.0-rc.00
28.0.00
28.0.0-rc.00
27.0.148
27.0.01
27.0.0-rc.00
26.0.07
26.0.0-alpha.10
26.0.0-alpha.00
25.1.05
25.1.0-beta.01
25.0.013
25.0.0-rc.20
25.0.0-rc.10
25.0.0-rc.00
24.0.013
23.0.10
23.0.07
23.0.0-rc.00
22.0.1-SNAPSHOT.2017.11.10
22.0.1-SNAPSHOT.2017.10.310
22.0.1-snapshot.2017.10.290
22.0.12
22.0.01
22.0.0-alpha.00
21.0.2-SNAPSHOT.d993f41d1
21.0.2-SNAPSHOT.dfc397531
21.0.210
21.0.11
21.0.00
20.0.01
20.0.0-rc.11
20.0.0-rc.00
19.0.52
19.0.40
19.0.31
19.0.20
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.00
18.0.01
18.0.0-rc.10
18.0.0-rc.00
1.0.30
1.0.23
1.0.10
1.0.1-rc.10
1.0.01
0.4.05
0.4.0-alpha.10
0.4.0-alpha.00
0.3.11
0.3.00
0.2.31
0.2.21
0.2.11
0.3.0-beta.00

Package Sidebar

Install

npm i jest-expo

Weekly Downloads

85,337

Version

52.0.3

License

MIT

Unpacked Size

116 kB

Total Files

38

Last publish

Collaborators

  • tsapeta
  • ide
  • lukmccall
  • szdziedzic
  • 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