xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

jest all in one

jest all in one

ES Modules & TypeScript & React

https://github.com/xgqfrms/FEAT/tree/master/jest

ES Modules

babel

$ yarn add -D babel-jest @babel/core @babel/preset-env

https://babeljs.io/docs/en/

// babel.config.js
module.exports = {
  presets: [
    [
      '@babel/preset-env',
      {
        targets: {
          node: 'current',
        },
      },
    ],
  ],
};

jest 23

TypeScript

$ yarn add -D @babel/preset-typescript

// babel.config.js
module.exports = {
  presets: [
    ['@babel/preset-env', {targets: {node: 'current'}}],
+    '@babel/preset-typescript',
  ],
};

React

https://jestjs.io/docs/en/tutorial-react

https://create-react-app.dev/

# create-react-app
$ yarn add -D react-test-renderer

# manual
$ yarn add -D jest babel-jest @babel/preset-env @babel/preset-react react-test-renderer

// babel.config.js
module.exports = {
  presets: ['@babel/preset-env', '@babel/preset-react'],
};
// package.json
  "dependencies": {
    "react": "<current-version>",
    "react-dom": "<current-version>"
  },
  "devDependencies": {
    "@babel/preset-env": "<current-version>",
    "@babel/preset-react": "<current-version>",
    "babel-jest": "<current-version>",
    "jest": "<current-version>",
    "react-test-renderer": "<current-version>"
  },
  "scripts": {
    "test": "jest"
  }

refs

https://jestjs.io/docs/en/getting-started#using-babel

https://github.com/facebook/jest/issues/8133#issuecomment-473792563

https://github.com/xgqfrms/FEAT/issues/1

webpack

https://jestjs.io/docs/en/webpack

parcel

https://parceljs.org/getting_started.html



©xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


posted @ 2020-08-24 00:17  xgqfrms  阅读(110)  评论(4编辑  收藏  举报