Open Jonnboy91 opened 7 months ago
:warning: | Missing Reproducible Example |
---|---|
:information_source: | We could not detect a reproducible example in your issue report. Please provide either:
|
Was able to mock it in my own jest.setup.ts file like this:
jest.mock('react-native/Libraries/Components/AccessibilityInfo/AccessibilityInfo', () => {
return {
_esModule: true,
default: {
addEventListener: jest.fn(),
announceForAccessibilityWithOptions: jest.fn(),
isScreenReaderEnabled: jest.fn(() => Promise.resolve(false)),
},
};
});
I am also facing similar issue with react native version 0.73.5.
Here how my jest.config.js
looks like:
module.exports = {
preset: 'react-native',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
clearMocks: true,
transform: {
'^.+\\.(js|jsx|ts|tsx)$': 'babel-jest'
},
transformIgnorePatterns: [
'node_modules/(?!@codler|(?!(jest-)?react-native)|@react-navigation|@sentry/react-native|native-base-shoutem-theme|@react-native-community|native-base)'
],
collectCoverage: true,
collectCoverageFrom: ['src/**/*.{js,jsx}'],
coverageReporters: ['html'], // json-summary
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
coverageDirectory: './coverage',
moduleNameMapper: {
'\\.(jpg|jpeg|png|gif|otf|webp|svg|ttf|mp4|webm|wav|mp3|m4a|aac)$':
'identity-obj-proxy'
},
moduleDirectories: ['node_modules', __dirname],
modulePathIgnorePatterns: ['node_modules']
babel.config.js
:
module.exports = (api) => {
const babelEnv = api.env();
const plugins = [];
plugins.push([
'babel-plugin-module-resolver',
{
root: ['./src']
}
]);
if (babelEnv !== 'development') {
plugins.push(['transform-remove-console']);
}
return {
presets: [
['module:@react-native/babel-preset'],
[
'@babel/preset-env',
{
targets: {
node: 'current'
}
}
]
],
plugins
};
};
Can someone look into this issue please or do I need to change anything in jest config?
+1
Description
When using AccessibilityInfo.announceForAccessibility no problems come when I run jest, but when I change it to AccessibilityInfo.announceForAccessibilityWithOptions I get:
TypeError: _reactNative.AccessibilityInfo.announceForAccessibilityWithOptions is not a function
I checked node_modules/react-native/jest/setup.js file I can see that under AccessibilityInfo there is no announceForAccessibilityWithOptions mocking, but when I change announceForAccessibility -> announceForAccessibilityWithOptions in that file then tests run without issues (not going to obviously leave it like this, just tested if that helps).I tried to mock announceForAccessibilityWithOptions within my own jest.setup file, but that created a lot of different issues.
Steps to reproduce
Use AccessibilityInfo.announceForAccessibilityWithOptions() and run jest and you'll get an issue
TypeError: _reactNative.AccessibilityInfo.announceForAccessibilityWithOptions is not a function
React Native Version
0.73.6
Affected Platforms
Build - MacOS
Output of
npx react-native info
Stacktrace or Logs
Reproducer
n/a
Screenshots and Videos
No response