Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
jest-expo
Advanced tools
The jest-expo package is a set of Jest presets tailored for testing Expo applications. It simplifies the setup and configuration needed to test React Native components and other Expo-specific features, making it easier to write and run tests for Expo projects.
Preset Configuration
The jest-expo package provides a preset configuration that you can use in your Jest configuration file. This preset includes all necessary settings to test Expo applications, such as transforming JavaScript and TypeScript files, handling static assets, and mocking native modules.
module.exports = { preset: 'jest-expo' };
Snapshot Testing
Snapshot testing is a feature that allows you to capture the rendered output of a component and compare it to a reference snapshot file. This helps ensure that your UI does not change unexpectedly.
import React from 'react';
import renderer from 'react-test-renderer';
import App from '../App';
test('App snapshot', () => {
const tree = renderer.create(<App />).toJSON();
expect(tree).toMatchSnapshot();
});
Mocking Native Modules
jest-expo makes it easy to mock native modules and Expo-specific APIs, allowing you to test components that rely on these modules without needing a physical device or emulator.
jest.mock('expo-constants', () => ({
manifest: {
extra: {
apiUrl: 'https://api.example.com'
}
}
}));
react-native-testing-library is a popular library for testing React Native components. It provides utilities to render components, query elements, and simulate user interactions. Compared to jest-expo, it focuses more on testing the behavior of components rather than configuration and setup.
Enzyme is a JavaScript testing utility for React that makes it easier to assert, manipulate, and traverse your React components' output. While it is not specific to React Native or Expo, it can be used in conjunction with other tools to test React Native components. It offers a different approach to testing compared to jest-expo, focusing on shallow rendering and component manipulation.
Jest is a delightful JavaScript testing framework with a focus on simplicity. It works with projects using Babel, TypeScript, Node.js, React, Angular, Vue.js, and Svelte. While jest-expo is built on top of Jest and provides Expo-specific configurations, Jest itself is a more general-purpose testing framework.
A Jest preset to painlessly test your Expo / React Native apps.
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 withexpo install
, but keep in mind that the SDK andjest-expo
are built against that version.
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
.
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
To test specific platforms you can use the following extensions:
-test.ios.*
, -test.native.*
-test.android.*
, -test.native.*
-test.web.*
-test.node.*
, -test.web.*
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"}
+ ]
},
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.
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.
49.0.0 — 2023-06-27
@react-native-community/datetimepicker
from 6.7.3
to 7.2.0
. (#23034 by @gabrieldonadel)@react-native-community/netinfo
from 9.3.7
to 9.3.10
. (#22892 by @douglowder)@react-native-masked-view/masked-view
from 0.2.8
to 0.2.9
. (#22875 by @gabrieldonadel)@react-native-picker/picker
from 2.4.8
to 2.4.10
. (#22919 by @keith-kurak)@react-native-segmented-control/segmented-control
from 2.4.0
to 2.4.1
. (#22911 by @keith-kurak)@shopify/flash-list
from 1.4.0
to 1.4.3
. (#22893 by @gabrieldonadel)@shopify/react-native-skia
from 0.1.172
to 0.1.196
. (#22900, #23036, #23157 by @kudo)lottie-react-native
from 5.1.4
to 5.1.6
. (#22868 by @alanjhughes)react-native-gesture-handler
from 2.10.1
to 2.12.0
. (#22621 by @aleqsio)react-native-maps
from 1.3.2
to 1.7.1
. (#22908 by @aleqsio)react-native-pager-view
from 6.1.2
to 6.2.0
. (#22892 by @douglowder)react-native-reanimated
from 2.14.4
to 3.3.0
. (#22907 by @kudo)react-native-safe-area-context
from 4.5.0
to 4.6.3
. (#23026 by @tsapeta)react-native-screens
from 3.20.0
to 3.22.0
. (#23022 by @tsapeta)react-native-svg
from 13.4.0
to 13.9.0
. (#22934 by @alanjhughes)react-native-view-shot
from 3.5.0
to 3.7.0
. (#23024 by @tsapeta))react-native-webview
from 11.26.0
to 13.2.2
. (#22913 by @aleqsio)expo-application
robolectric
to 4.10
and junit
to 4.13.2
. (#22395 by @josephyanks)expo-battery
robolectric
to 4.10
and junit
to 4.13.2
. (#22395 by @josephyanks)expo-clipboard
robolectric
to 4.10
. (#22395 by @josephyanks)expo-crypto
robolectric
to 4.10
and junit
to 4.13.2
. (#22395 by @josephyanks)expo-location
com.google.android.gms:play-services-location
to 21.0.1
and io.nlopez.smartlocation:library
to 3.3.3
(#22468 by @josephyanks)expo-media-library
robolectric
to 4.10
. (#22395 by @josephyanks)expo-modules-core
robolectric
to 4.10
and junit
to 4.13.2
. (#22395 by @josephyanks)expo-sms
robolectric
to 4.10
and junit
to 4.13.2
. (#22395 by @josephyanks)expo-web-browser
robolectric
to 4.10
. (#22395 by @josephyanks)expo-blur
expo-face-detector
expo-gl
enableExperimentalWorkletSupport
to use GLView from Reanimated worklet. (#22613 by @wkozyra95)expo-file-system
UploadProgressData.totalByteSent
field. (#22277 by @gabrieldonadel)expo-linking
detach.scheme
schemes (ExpoKit). (#22848 by @EvanBacon)expo-notifications
ExpoPushTokenOptions.experienceId
field. (#22303 by @gabrieldonadel)expo-battery
useBatteryLevel
, useBatteryState
, useLowPowerMode
, and usePowerState
. (#22646 by @Adam-Schlichtmann)expo-blur
expo-brightness
expo-clipboard
ClipboardPasteButton
view that uses UIPasteControl
. (#22823 by @alanjhughes)expo-device
deviceType
constant. (#21633 by @robertherber)expo-document-picker
expo-gl
expo-file-system
expo-image-picker
expo-localization
expo-media-library
expo-screen-capture
expo-sharing
UIDocumentInteractionController
to UIActivityViewController
which provides more features. (#22012 by @alanjhughes)expo-modules-core
ReactActivityHandler.getDelayLoadAppHandler
interface on Android. (#20273 by @kudo)Image
and Media
rather than Fetch
. (#23058 by @kudo)expo-speech
expo-print
expo-screen-orientation
expo-secure-store
expo-sqlite
Promise
based execAsync
and transactionAsync
functions. (#23109 by @kudo)expo-application
expo-asset
@react-native/assets-registry
module not found issue on Web. (#21469 by @kudo)expo-background-fetch
expo-barcode-scanner
expo-av
expo-battery
expo-blur
expo-brightness
expo-branch
expo-calendar
expo-cellular
expo-clipboard
expo-device
expo-document-picker
Record
on Android. (#21588 by @alanjhughes)copyToCacheDirectory
on iOS. (#23102 by @aleqsio)expo-camera
expo-contacts
expo-face-detector
expo-gl
expo-file-system
expo-haptics
expo-image-loader
expo-crypto
expo-intent-launcher
expo-image-picker
.png
when opening .bmp
files and selecting any quality in ImagePickerOptions
. (#21361 by @behenate)MediaTypeOptions.All
(#22606 by @fobos531)expo-constants
expo-keep-awake
expo-font
expo-mail-composer
expo-location
expo-local-authentication
NSFaceIDUsageDescription
in the Info.plist. (#21500 by @alanjhughes)expo-localization
getCalendars
on Web. (#22003 by @aleqsio)expo-linear-gradient
expo-media-library
expo-random
expo-notifications
expo-screen-capture
expo-sharing
expo-modules-core
URL
type to support unencoded UTF8 urls and file paths. (#21139 by @tsapeta)#
getting cut off. (#21326 by @lukmccall)URL
object. (#21569 by @tsapeta)ReadableNativeMap
cannot be cast to the Record
. (#21773 by @lukmccall)JavaScriptObject
argument and view props. (#22427 by @lukmccall)Color
converter doesn't work on devices with SDK version below 26. (#22191 by @lukmccall)View cannot be cast to ViewGroup
exception on Android. (#23264 by @lukmccall)URL
type that failed despite receiving a string that contained a valid URL. (#23331 by @alanhughes) (#23331 by @alanjhughes)Content-Length
header. (#23405 by @kudo)SoLoader
does not work on Android. (#23415 by @kudo)expo-network
expo-sensors
expo-speech
expo-permissions
expo-print
expo-screen-orientation
rootViewController
value. (#23039 by @gabrieldonadel)Info.plist
instead of being set to portrait. (#23456 by @behenate)expo-image-manipulator
expo-secure-store
expo-store-review
expo-sms
expo-sqlite
expo-task-manager
expo-video-thumbnails
unimodules-app-loader
expo-web-browser
expo-camera
Remote JS debugger
option from Expo Go menu when using SDK 49 or above. (#22027 by @gabrieldonadel)expo-barcode-scanner
com.google.android.gms:play-services-vision
with com.google.mlkit:barcode-scanning
. (#22107 by @toshiyuki-suzuki-yukashikado)expo-auth-session
useProxy
option. (#21313 by @gabrieldonadel)makeRedirectUriAsync
with makeRedirectUri
. (#21314 by @gabrieldonadel)promptAsync
when the useProxy
option is used. (#21367 by @gabrieldonadel)startAsync
from js doc. (#23150 by @alanhughes) (#23150 by @alanjhughes)expo-calendar
expo-document-picker
getDocumentAsync
. (#23135 by @alanjhughes)expo-gl
expo-file-system
expo-crypto
randomUUID
method. (#21187 by @KiwiKilian)expo-constants
Constants.deviceYearClass
and Constants.platform.ios.model
. These properties now live on expo-device
. (#23068 by @brentvatne)expo-linking
expo-mail-composer
expo-location
LocationRequest
constructor and replaced with LocationRequest.Builder
. (#22653 by @alanjhughes)expo-notifications
expo-screen-capture
expo-modules-core
fallbackCallback
optional in the registerForActivityResult
method. (#21661 by @lukmccall)jsi::WeakObject
for weak objects on Hermes. (#21986 by @tsapeta)proxiedProperties
prop. (#22280 by @tsapeta)JavaScriptValue.kind
public. (#22386 by @lukmccall)androidx.activity:activity-ktx
to 1.7.1
and androidx.fragment:fragment-ktx
to 1.5.7
#22658 by @fobos531ExpoReactDelegate
and ExpoReactDelegateHandler
to fix issues with versioning in Expo Go. (#23229 by @tsapeta)expo-screen-orientation
expo-secure-store
NSFaceIDUsageDescription
key in the set
function. (#23275 by @alanjhughes)expo-task-manager
defineTask
to accept type arguments. (#21958 by @kazuma0129)FAQs
A Jest preset to painlessly test your Expo / React Native apps.
The npm package jest-expo receives a total of 289,856 weekly downloads. As such, jest-expo popularity was classified as popular.
We found that jest-expo demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 28 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.