Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Taro3.6.24模板项目创建后运行测试报错 #38

Open
tangbzai opened this issue Mar 2, 2024 · 5 comments
Open

Taro3.6.24模板项目创建后运行测试报错 #38

tangbzai opened this issue Mar 2, 2024 · 5 comments

Comments

@tangbzai
Copy link

tangbzai commented Mar 2, 2024

问题描述:

taro 3.6.24版本的模板项目运行测试会报找不到history的错误。

  • 3.6.23开始有这个问题,回退到3.6.22可以解决该问题

错误信息:

 FAIL  __tests__/index.test.js
  ● Test suite failed to run

    TypeError: Cannot read properties of undefined (reading 'history')

    > 1 | import TestUtils from '@tarojs/test-utils-react'
        | ^
      2 |
      3 | describe('Testing', () => {
      4 |

      at Object.history (node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]/node_modules/@tarojs/router/dist/index.js:47:21)
      at Object.<anonymous> (node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]/node_modules/@tarojs/taro-h5/src/api/taro.ts:37:3)        
      at Object.<anonymous> (node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]/node_modules/@tarojs/taro-h5/dist/index.js:2815:37)       
      at Object.<anonymous> (node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@tarojs+helper@3._gd4weot4ybe46ivih6r3y7qjiq/node_modules/@tarojs/test-utils-react/dist/jest/runtime/taro-h5.js:1:1)
      at Object.<anonymous> (node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@[email protected]__fvjn2myy6sdebjsqurs77ec2si/node_modules/@tarojs/components/dist/components/helper.js:1:1)
      at Object.<anonymous> (node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@[email protected]__fvjn2myy6sdebjsqurs77ec2si/node_modules/@tarojs/components/dist/components/taro-ad-core.js:2:1)
      at Object.<anonymous> (node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@[email protected]__fvjn2myy6sdebjsqurs77ec2si/node_modules/@tarojs/components/dist/components/index.js:2:1)
      at Object.<anonymous> (node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]/node_modules/@tarojs/router/dist/tabbar.js:1:1)
      at Object.<anonymous> (node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]/node_modules/@tarojs/router/dist/index.js:2:1)
      at Object.<anonymous> (node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected]_@tarojs+helper@3._gd4weot4ybe46ivih6r3y7qjiq/node_modules/@tarojs/test-utils-react/dist/index.js:41:18)
      at Object.<anonymous> (__tests__/index.test.js:1:1)
      at tryCatch (node_modules/.pnpm/@[email protected]/node_modules/@babel/runtime/helpers/regeneratorRuntime.js:45:16)
      at Generator._invoke (node_modules/.pnpm/@[email protected]/node_modules/@babel/runtime/helpers/regeneratorRuntime.js:133:17)
      at Generator.next (node_modules/.pnpm/@[email protected]/node_modules/@babel/runtime/helpers/regeneratorRuntime.js:74:21)
      at asyncGeneratorStep (node_modules/.pnpm/@[email protected]/node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
      at _next (node_modules/.pnpm/@[email protected]/node_modules/@babel/runtime/helpers/asyncToGenerator.js:22:9)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        15.156 s
Ran all test suites.
 ELIFECYCLE  Test failed. See above for more details.

复现步骤:

  1. 使用@tarojs/cli创建模板项目 (react+pnpm+ts+less+github+默认模板)
  2. 项目创建完成并安装完成依赖后运行pnpm test
@jxgzzztang
Copy link

有解决方案吗?

@tangbzai
Copy link
Author

有解决方案吗?

目前没有很好的解决方案,只能回退Taro版本到3.6.22或者不使用这个库。

@tangbzai
Copy link
Author

我目前定位到问题是出在 Taro的 #15094 pr 导致的报错。

这个合并里修改了@tarojs/routercreateRouter 函数(在函数前面增加了一个history参数)而这个库的代码未做对应修改导致的问题。
具体代码片段:packages/taro-router/src/router/spa.ts
这个库需要调整的位置:

@heiazu 麻烦大佬看看如何修改

@jxgzzztang
Copy link

有解决方案吗?

目前没有很好的解决方案,只能回退Taro版本到3.6.22或者不使用这个库。

那只能暂时回退版本了

@kunkuntang
Copy link

还没解决吗。。。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants