Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
OrganizationAdvent CalendarQiitadon (β)
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

React Native, Expo, Jest, TypeScript 的設定 (筆記)

More than 1 year has passed since last update.


安裝各種需要的 packages

安裝和 React Native, Jest, Expo, TypeScript 定義檔 所有相關的玩意:

yarn add -D jest jest-expo ts-jest react-test-renderer @types/jest @types/react-test-renderer

Jest 的設定

package.json 檔案中,設定 "jest" 項下的各種參數

  "... 省略 ...",

  "jest": {
    "preset": "jest-expo",
    "transform": {
      "^.+\\.js$": "<rootDir>/node_modules/react-native/jest/preprocessor.js",
      "^.+\\.tsx?$": "ts-jest"
    "testMatch": [
    "moduleFileExtensions": [
    "globals": {
      "ts-jest": {
        "tsConfig": {
          "jsx": "react"

  "... 省略 ..."

追加自定義 script

一樣是在 package.json 中, scripts 段加入這些:

  "... 省略 ...",

  "scripts": {
    "... 省略 ...",

    "lint:fix": "eslint --fix '*/**/*.{js,ts,tsx}'",
    "test": "yarn lint:fix && yarn tsc-test && yarn jest",
    "tsc-test": "tsc --project . --noEmit",
    "jest": "jest",

    "... 省略 ...",

  "... 省略 ..."


yarn test



iOS Developer from 🇹🇼
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away