Browse Source

docs: documentation for Jest support (#27003)

pull/27064/head
Jesus The Hun 4 years ago
committed by GitHub
parent
commit
f3f5b66957
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      docs/react/getting-started.en-US.md
  2. 12
      docs/react/use-with-create-react-app.en-US.md

10
docs/react/getting-started.en-US.md

@ -97,6 +97,16 @@ During actual real-world project development, you will most likely need a develo
- [d2-admin](https://github.com/d2-projects/d2-admin)
- More scaffolds at [Scaffold Market](http://scaffold.ant.design/)
## Test with Jest
If you use `create-react-app` follow the instructions [here](/docs/react/use-with-create-react-app#Test-with-Jest) instead.
Jest does not support `esm` modules, and Ant Design uses them. In order to test your Ant Design application with Jest you have to add the following to your Jest config :
```json
"transform": { "^.+\\.(ts|tsx|js|jsx)?$": "ts-jest" }
```
## Import on Demand
`antd` supports tree shaking of ES modules, so using `import { Button } from 'antd';` would drop js code you didn't use.

12
docs/react/use-with-create-react-app.en-US.md

@ -82,6 +82,18 @@ Ok, you should now see a blue primary button displayed on the page. Next you can
We are successfully running antd components now, go build your own application!
## Test with Jest
`create-react-app` comes with `jest` built in. Jest does not support `esm` modules, and Ant Design uses them. In order to test your Ant Design application with Jest you have to add the following to your `package.json` :
```json
"jest": {
"transformIgnorePatterns": [
"/node_modules/(?!antd|@ant-design|rc-.+?|@babel/runtime).+(js|jsx)$"
]
}
```
## Advanced Guides
In the real world, we usually have to modify default webpack config for custom needs such as themes. We can achieve that by using [craco](https://github.com/gsoft-inc/craco) which is one of create-react-app's custom config solutions.

Loading…
Cancel
Save