question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Default to React Native Jest Preprocessor

See original GitHub issue

🚀 Feature Proposal

If using the react-native preset, the transformer should default to the react-native/jest/preprocessor.js. If left off, it doesn’t transform anything. And React Native defaults to its own transformer so adding an extra babel.config.js just for tests seems redundant when all the pieces are already there.

Motivation

One less package (metro-jest-babel-resolver or something like that) and one less config file for default RN projects (babel.config.js)

Example

The only thing you need to get a simple RN project up and running in Jest should be:

{
  preset: "react-native"
}

Currently, you need this extra line:

    "preset": "react-native",
    "transform": {
      "\\.(js|ts|tsx)$": "./node_modules/react-native/jest/preprocessor.js"
    },

Pitch

Makes the requirements to use Jest for React Native even smaller and more concise.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:21

github_iconTop GitHub Comments

2reactions
SimenBcommented, Dec 3, 2020

Should be fixed now: #10910

1reaction
SimenBcommented, Dec 3, 2020

You need to build jest first. Run yarn build:js in root, then you should be able to run the example.

This is covered by the contribution guide, fwiw

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using with React Native | ts-jest - GitHub Pages
To use ts-jest with React Native + TypeScript and Babel 7, you'll first need ... const { defaults: tsjPreset } = require('ts-jest/presets')
Read more >
React Native with Typescript and Jest is broken after 0.57 ...
If I use "presets": ["module:metro-react-native-babel-preset"] then tests are broken but production/development is working. Not sure why it's ...
Read more >
Configuring Jest
The Jest philosophy is to work great by default, but sometimes you just need more configuration power.
Read more >
How to use the ts-jest/presets.defaults.transform function in ts ...
To help you get started, we've selected a few ts-jest/presets.defaults.transform examples, based on popular ways it is used in public projects.
Read more >
Using TypeScript With React Native - Jan Hesters
Jest is already installed by default . We do need to install ts-jest, though. npm install --save-dev ts-jest.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found