【问题标题】:Can't test Styled Component in Jest无法在 Jest 中测试样式化组件
【发布时间】:2018-10-25 13:07:43
【问题描述】:

尝试运行简单的快照测试时,我得到以下信息:

TypeError: _styledComponents2.default.View is not a function

      2 | import styled from "styled-components";
      3 |
    > 4 | const ButtonContainer = styled.View`
      5 |   flex-direction: row;
      6 |   align-items: center;
      7 |   justify-content: center;

我试过了:

"moduleNameMapper": {
      "styled-components":
        "<rootDir>/node_modules/styled-components/dist/styled-components.native.cjs.js"
    }

同时添加https://github.com/styled-components/jest-styled-components

但我没有这样的运气。

【问题讨论】:

    标签: react-native jestjs styled-components


    【解决方案1】:

    确保“moduleNameMapper”对象在“jest”块内。

    【讨论】:

      猜你喜欢
      • 2021-11-19
      • 2020-02-29
      • 2019-05-30
      • 2020-03-07
      • 2021-11-25
      • 2019-05-13
      • 2020-04-17
      • 2019-01-17
      • 2018-07-08
      相关资源
      最近更新 更多