无法在Jest中测试Styled Component

时间:2018-05-15 16:00:27

标签: react-native jestjs styled-components

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

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

但我没有运气。

1 个答案:

答案 0 :(得分:0)

确保“ moduleNameMapper”对象位于“ jest”块内。