使用Wordpress和Gutenberg-我尝试编写一个简单的笑话测试。
tests/unit/blocks/spacer/index.test.js
● Test suite failed to run
Jest encountered an unexpected token
This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.
By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
Here's what you can do:
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/en/configuration.html
Details:
SyntaxError: /Users/username/Local Sites/beansdev/app/public/wp-content/plugins/beanblocks/src/blocks/spacer/components/simple.js: Unexpected token (24:3)
22 |
23 | return (
> 24 | <div
| ^
25 | style={ {
26 | color: spacerDividerColor
27 | } }
at Parser.raise (node_modules/@babel/parser/lib/index.js:3851:17)
at Parser.unexpected (node_modules/@babel/parser/lib/index.js:5167:16)
at Parser.parseExprAtom (node_modules/@babel/parser/lib/index.js:6328:20)
at Parser.parseExprSubscripts (node_modules/@babel/parser/lib/index.js:5914:23)
at Parser.parseMaybeUnary (node_modules/@babel/parser/lib/index.js:5894:21)
at Parser.parseExprOps (node_modules/@babel/parser/lib/index.js:5781:23)
at Parser.parseMaybeConditional (node_modules/@babel/parser/lib/index.js:5754:23)
at Parser.parseMaybeAssign (node_modules/@babel/parser/lib/index.js:5701:21)
at Parser.parseParenAndDistinguishExpression (node_modules/@babel/parser/lib/index.js:6466:28)
at Parser.parseExprAtom (node_modules/@babel/parser/lib/index.js:6260:21)
我尝试了以下建议:
https://github.com/WordPress/gutenberg/issues/13364
https://torquemag.io/2018/11/sharing-react-components-with-gutenberg/
有什么建议或其他信息可以帮助解决此问题?