React native Jest测试用例使用StyleSheet.create失败

React native Jest测试用例使用StyleSheet.create失败,react-native,jestjs,React Native,Jestjs,我目前面临的一个问题是,every pages Stylesheet.create是失败的原因,但不完全确定原因是什么。。但有人能给我一个解释或解决方案吗 还有一件事,没有Ezyme(我使用react native 0.56,我还没有找到Ezyme安装文件。)我可以基于一个类来模拟一个按钮,比如一个主页上有两个按钮,作为一个测试用例,两个按钮都按下吗 ● 测试套件无法运行 TypeError: Cannot read property 'create' of undefined 162 |

我目前面临的一个问题是,every pages Stylesheet.create是失败的原因,但不完全确定原因是什么。。但有人能给我一个解释或解决方案吗

还有一件事,没有Ezyme(我使用react native 0.56,我还没有找到Ezyme安装文件。)我可以基于一个类来模拟一个按钮,比如一个主页上有两个按钮,作为一个测试用例,两个按钮都按下吗

● 测试套件无法运行

TypeError: Cannot read property 'create' of undefined

  162 | }
  163 |
> 164 | const styles = StyleSheet.create({
      |                           ^
  165 |     container: {
  166 |         flex: 1,
  167 |         justifyContent: 'center',

  at Object.<anonymous> (components/landingpage.js:164:27)
  at Object.<anonymous> (__tests__/landingpage.spec.js:3:1)
TypeError:无法读取未定义的属性“create”
162 | }
163 |
>164 | const styles=StyleSheet.create({
|                           ^
165 |集装箱:{
166 |弹性:1,
167 |为内容辩护:“中心”,
at对象。(组件/landingpage.js:164:27)
at对象。(\uuuuu测试\uuuu/landingpage.spec.js:3:1)
您需要模拟它

jest.mock('react-native', () => {
    let items = {};
        StyleSheet: {
            create: () => ({})
        },
    }
});

阿明答案的正确语法:

jest.mock('react-native', () => {
  return {
    StyleSheet: {
      create: () => ({}),
    },
  };
});