When I try to make fun of react-native-sound with Jest, I get the following error:
import Sound from 'react-native-sound';
try {
console.log('Sound: ' + JSON.stringify(Sound));
_trackPlaying = new Sound('path', Sound.LIBRARY, error => { });
} catch (error) {
console.log('error: ' + JSON.stringify(error));
}
jest.mock('react-native-sound', () => ({
Sound: jest.fn((path, type, callback) => {
})
}));
//package.json
{
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-jest": "^21.2.0",
"babel-plugin-transform-flow-strip-types": "^6.22.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-flow": "^6.23.0",
"flow": "^0.2.3",
"jest": "^21.2.1"
},
"jest": {
"modulePathIgnorePatterns": [
"__mocks__/"
]
},
"dependencies": {
"react-native-sound": "^0.10.4"
}
}
As an alternative, I tried setting up a manual layout in a separate file ( __mock__) with a similar hit:
const Sound = jest.genMockFromModule('react-native-sound');
Sound = (path, type, callback) => {
console.log("mocked");
}
module.exports = Sound;
jest.mock('react-native-sound');
Any recommendations or recommendations are welcome. Many thanks!
source
share