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

引入了react-dev-inspector后,我的测试通过不了? #14

Closed
alexya opened this issue Jan 20, 2021 · 2 comments
Closed

引入了react-dev-inspector后,我的测试通过不了? #14

alexya opened this issue Jan 20, 2021 · 2 comments

Comments

@alexya
Copy link

alexya commented Jan 20, 2021

refer to:
https://v2ex.com/t/746186

大神,我引用了你的这个库之后,原先能够通过的测试,就没有办法通过了。能帮忙瞧一下,哪里配置出了问题么?

谢谢

@zthxxx
Copy link
Owner

zthxxx commented Jan 21, 2021

@alexya jest 如果要跑 jsx / tsx 文件,最好也编译一下,保证和 webpack loader 处理后一致,如 jest 有 transform 字段配置,通常会配置 ts-jest 或 babel-jest

https://jestjs.io/docs/en/configuration#transform-objectstring-pathtotransformer--pathtotransformer-object

  // demo
  transform: {
    '^.+\\.(t|j)sx?$': [
      'ts-jest',
      {
        babelConfig: {
          presets: ['@babel/preset-react', '@babel/preset-env'],
          plugins: [
            'react-hot-loader/babel',
            '@babel/plugin-proposal-class-properties',
            '@babel/plugin-transform-runtime',
          ],
        },
      },
    ],
  },

@zthxxx
Copy link
Owner

zthxxx commented Jan 21, 2021

或者在 jest 环境下就不去 import 这个库呢,

因为这个库导出的给 react 的组件是 ES module 类型的 (导出的给 node 用的 plugin 这些才是 commonjs 的),

所以目前在你的 jest 下如果不经过 babel / esm 这些转换就不支持

@zthxxx zthxxx closed this as completed Jan 22, 2021
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

2 participants