Does not work with jest
See original GitHub issueUse craco test
results in the error:
Test suite failed to run
/Users/xxx/sources/proj/node_modules/antd/es/card/style/index.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import '../../style/index.less';
^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Unexpected string
10 | AutoComplete,
11 | message,
> 12 | Select
| ^
13 | } from "antd";
14 | import axios from "axios";
Problem resolved when I changed back to react-scripts test
.
BTW, craco start
works fine.
Env
“craco-antd”: “^1.9.3”, “@craco/craco”: “^3.2.3”, “antd”: “^3.11.6”, “react-scripts”: “^2.1.1”
// craco.config.js
const CracoAntDesignPlugin = require("craco-antd");
module.exports = {
plugins: [
{
plugin: CracoAntDesignPlugin,
options: {
customizeTheme: {
"@primary-color": "#8440bd"
}
}
}
]
};
Thank you!
Issue Analytics
- State:
- Created 5 years ago
- Comments:21 (6 by maintainers)
Top Results From Across the Web
Troubleshooting - Jest
Use this guide to resolve issues with Jest. Tests are Failing and You Don't Know Why. Try using the debugging support built into...
Read more >npm test/ jest not working - Stack Overflow
When I do npm test /jest, I am getting the following error: > @ test /Users/suparnasoman/Downloads/create-react-app-master > node packages/react ...
Read more >Troubleshooting · Jest
Use this guide to resolve issues with Jest. Tests are Failing and You Don't Know Why #. Try using the debugging support built...
Read more >Fetch do not work on Jest · Issue #2071 · facebook/jest - GitHub
This test is inside a react native project, I have a very long timeout. jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000; .
Read more >Should you use jest as a testing library? - Backend Cafe
jest is a great testing framework, and it works well for frontend applications, but you could face some issues if your dependencies rely...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This can be resolved by setting jest to transform any modules that need it, by adding it to the
craco.config.js
jest section:There might be a better solution, but this works for me, as it was just an extension of a fix I needed for the same issue with
monaco-editor
. I’m not sure if it can be fixed by default, as it relies on a config override callback, but it can at least be documented.At this stage I’m just doing initial setup of antd, so caveat that I haven’t actually seriously tested this beyond making sure my current simple tests pass! It’s also a fairly blunt fix, as it means antd and deps needs to be transformed as part of tests, which can add a good 10+ seconds to the initial cycle.
yea, just cloned your poc and tried some scenarios
react-scripts test
passes withimport Button from 'antd/lib/button'
craco test
passes withimport Button from 'antd/lib/button'
react-scripts test
passes withimport { Button } from 'antd'
craco test
fails withimport { Button } from 'antd'