Umi: ReferenceError: __UMI_HTML_SUFFIX is not defined

Created on 11 Oct 2019  ·  3Comments  ·  Source: umijs/umi

What happens?

使用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.

相关环境信息

  • Umi 版本:2.9.0
  • Node 版本:v10.16.0
  • 操作系统:windows7
type(bug) wontfix

Most helpful comment

同样遇到这个问题。
暂时在jest.config.js里定义一下这个全局变量解决。

globals: {
    __UMI_HTML_SUFFIX: false
}

不过这个变量确实不应该暴露出来的

All 3 comments

同样

同样遇到这个问题。
暂时在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.

Was this page helpful?
0 / 5 - 0 ratings