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
// 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
# 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 发布文章使用:只允许注册用户才可以访问!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/13551549.html
未经授权禁止转载,违者必究!