rnx-kit/packages/jest-preset
renovate[bot] 57013d2191
fix(deps): update eslint (major) (#3394)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Tommy Nguyen <4123478+tido64@users.noreply.github.com>
2024-10-17 14:41:52 +00:00
..
private chore: move Jest config to break circular dependency (#2787) 2023-11-06 16:39:51 +01:00
src test(jest-preset): update tests to look for `@react-native/babel-preset` (#3340) 2024-09-10 17:23:37 +00:00
test test(jest-preset): update tests to look for `@react-native/babel-preset` (#3340) 2024-09-10 17:23:37 +00:00
CHANGELOG.md RELEASING: Releasing 44 package(s) (#3342) 2024-09-11 08:59:50 +02:00
README.md docs: automate removal of badges from READMEs (#2324) 2023-04-14 08:24:28 +02:00
eslint.config.js fix(deps): update eslint (major) (#3394) 2024-10-17 14:41:52 +00:00
jest-preset.js feat: add 'rnx-test' to cli and introduce @rnx-kit/jest-preset (#433) 2021-07-29 19:36:57 +00:00
package.json fix(deps): update eslint (major) (#3394) 2024-10-17 14:41:52 +00:00
tsconfig.json chore(metro-config): don't output unused `.d.ts` files (#3142) 2024-05-14 08:15:26 +00:00
typescript-esm-resolver.cjs test(build): allow tests without building (#2308) 2023-03-22 11:38:18 +00:00

README.md

@rnx-kit/jest-preset

Build npm version

A Jest preset with support for React Native platform-specific extensions and TypeScript.

Usage

In a TypeScript-only Package (Non-React Native)

Add preset: "@rnx-kit/jest-preset" to your Jest config:

 module.exports = {
+  preset: "@rnx-kit/jest-preset",
   ...
 };

@rnx-kit/jest-preset will detect that you're not targeting React Native and exclude any React Native specific configurations.

In a React Native Package

There are three ways to use this preset when targeting React Native, depending on your personal preference.

Single jest.config.js

If you prefer to use a single Jest config, you can provide the target platform via an environment variable. First, add preset: "@rnx-kit/jest-preset" to your Jest config:

 module.exports = {
+  preset: "@rnx-kit/jest-preset",
   ...
 };

Then specify the target platform when running Jest:

RN_TARGET_PLATFORM=ios npm run jest

Multiple jest.config.js

Alternatively, you can have a Jest config file for each platform, e.g.:

// jest.config.ios.js
module.exports = require("@rnx-kit/jest-preset")("ios", {
  ...
});

Then specify the config file to use when running Jest:

npm run jest --config jest.config.ios.js

Use @rnx-kit/cli

You can specify the target platform using the rnx-test command provided by @rnx-kit/cli. First, add preset: "@rnx-kit/jest-preset" to your Jest config:

 module.exports = {
+  preset: "@rnx-kit/jest-preset",
   ...
 };

Then specify the target platform when running rnx-test:

npm run react-native rnx-test --platform ios

In an Out-of-Tree Platform Package

Add preset: "@rnx-kit/jest-preset" to your Jest config:

 module.exports = {
+  preset: "@rnx-kit/jest-preset",
   ...
 };

The target platform will be deduced by reading react-native.config.js at the package root.