首页 > 解决方案 > _reactNative.UIManager.setLayoutAnimationEnabledExperimental 不是函数

问题描述

我正在尝试测试具有此函数调用的 react-native 组件。

  UIManager.setLayoutAnimationEnabledExperimental(true);

使用 @testing-library/react-native 渲染此组件时出现此错误。

_reactNative.UIManager.setLayoutAnimationEnabledExperimental is not a function

我尝试使用 jest spyOn 模拟该函数

import { UIManager } from 'react-native';
...
...
  beforeEach(() => {
   jest
  .spyOn(UIManager, 'setLayoutAnimationEnabledExperimental')
  .mockImplementation(jest.fn());
  })

仍然得到同样的错误,无论如何我可以模拟这个功能?

标签: react-nativejestjsreact-testing-libraryreact-native-testing-libraryreact-testing

解决方案


推荐阅读