使用umi test 测试一个使用了umi/router的组件,测试用例不通过
请使用
yarn create umi创建,并上传到你的 GitHub 仓库
https://github.com/ironyfive/umi-router-repo
yarn 安装依赖
yarn run start
umi test
PASS src/layouts/__tests__/index.test.tsx
FAIL src/pages/__tests__/index.test.tsx
● Test suite failed to run
ReferenceError: __UMI_HTML_SUFFIX is not defined
1 | // create history
> 2 | const history = require('umi/lib/createHistory').default({
| ^
3 | basename: window.routerBase,
4 | });
5 | window.g_history = history;
at Object._default [as default] (node_modules/umi/lib/createHistory.js:17:3)
at Object.<anonymous> (src/pages/.umi/history.js:2:17)
at Object.require (node_modules/umi/lib/router.js:13:39)
at Object.require (node_modules/umi/router.js:1:18)
at Object.<anonymous> (src/pages/index.tsx:3:1)
at Object.<anonymous> (src/pages/__tests__/index.test.tsx:2:1)
Test Suites: 1 failed, 1 passed, 2 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 4.534s
Ran all test suites.
同样
同样遇到这个问题。
暂时在jest.config.js里定义一下这个全局变量解决。
globals: {
__UMI_HTML_SUFFIX: false
}
不过这个变量确实不应该暴露出来的
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Most helpful comment
同样遇到这个问题。
暂时在
jest.config.js里定义一下这个全局变量解决。不过这个变量确实不应该暴露出来的