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

Taro 组件使用 Enzyme 的 mount / render 方法做 UI 测试 #8239

Closed
P233 opened this issue Dec 10, 2020 · 1 comment
Closed

Taro 组件使用 Enzyme 的 mount / render 方法做 UI 测试 #8239

P233 opened this issue Dec 10, 2020 · 1 comment
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x

Comments

@P233
Copy link

P233 commented Dec 10, 2020

相关平台

微信小程序

复现仓库

https://github.com/P233/jest-in-taro
小程序基础库: 最新版本
使用框架: React

复现步骤

问题描述:Enzyme 的 mount 与 render 无法引入作为测试的 HomePage 组件。 报错内容:Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

尝试将 HomePage (./src/pages/index/index.jsx) 中 Taro 的 组件替换为 ,可以成功执行测试,只是警告 The tag is unrecognized in this browser. If you meant to render a React component, start its name with an uppercase letter.。

期望结果

能够使用 Jest 完成 Taro 组件的 UI 测试

实际结果

报错,无法执行

环境信息

  Taro CLI 3.0.18 environment info:
    System:
      OS: macOS 11.0.1
      Shell: 3.1.2 - /usr/local/bin/fish
    Binaries:
      Node: 14.15.1 - /usr/local/bin/node
      npm: 6.14.8 - /usr/local/bin/npm
    npmPackages:
      @tarojs/components: 3.0.18 => 3.0.18
      @tarojs/mini-runner: 3.0.18 => 3.0.18
      @tarojs/react: 3.0.18 => 3.0.18
      @tarojs/runtime: 3.0.18 => 3.0.18
      @tarojs/taro: 3.0.18 => 3.0.18
      @tarojs/webpack-runner: 3.0.18 => 3.0.18
      babel-preset-taro: 3.0.18 => 3.0.18
      eslint-config-taro: 3.0.18 => 3.0.18
      react: ^16.10.0 => 16.14.0
    npmGlobalPackages:
      typescript: 4.1.2
@taro-bot2 taro-bot2 bot added F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x labels Dec 10, 2020
@ZakaryCode
Copy link
Contributor

Jest 参考文档

该文档方法提供给 Taro 3.4.0+

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x
Projects
None yet
Development

No branches or pull requests

2 participants