我經常遇到這個錯誤。Jest測試 - 意外的令牌錯誤
FAIL src\__tests__\app-test.js
? Test suite failed to run
C:/工作/保險POC /前端/臀/登錄/ SRC/__測試__/APP-test.js:意外令牌(105:28)
104 | test('App should render',() => {
> 105 | const appTest = shallow(<h1>Welcome</h1>);
| ^
106 | expect(appTest).toBeDefined();
107 | })
108 |
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 7.3s
Ran all test suites.
問題似乎是轉換成JSX。無論淺層()中的元素是什麼,它都會拋出相同的「意外標記」錯誤。請提出一些解決方法或可以解決問題的配置更改。
我曾嘗試:
NPM安裝通天塔 - 插件 - 轉換 - 反應 - JSX和包括.babelrc插件
你在你的'.babelrc'文件中有'react'和'es2015',並且是根文件夾中的'.babelrc'文件嗎? – Purgatory