我正在使用 wix 的 expo 34 和react-native-ui-lib并且在为我的组件设置 jest 测试时遇到问题。问题似乎出现在wix 库的链接中
function setStatusBarHeight() {
statusBarHeight = isIOS ? 20 : StatusBarManager.HEIGHT;
if (isIOS) {
// override guesstimate height with the actual height from StatusBarManager
StatusBarManager.getHeight(data => (statusBarHeight = data.height));
}
}
类型错误:StatusBarManager.getHeight 不是函数
TypeError: StatusBarManager.getHeight is not a function 如果我只是更改它并返回 42 我的测试可以运行。
有什么办法可以StatusBarManager.getHeight
开玩笑吗?
我试图jest-setup.js
在我的根文件夹中创建
import { NativeModules } from 'react-native';
NativeModules.StatusBarManager = {getHeight: jest.fn()};
// mock native modules
jest.mock('@react-native-community/blur', () => {});
但它没有用。我的电流jest.config.js
module.exports = {
preset: "jest-expo",
moduleFileExtensions: ['js','jsx','json', 'ts', 'tsx'],
transform: {
"^.+\\.(js|jsx|ts|tsx)$": "babel-jest"
},
testMatch: [
"**/*.test.ts?(x)"
],
}