//jest config
{
"preset": "react-native",
"transform": {
"^.+\\.(js)$": "<rootDir>/node_modules/react-native/jest/preprocessor.js"
}
}
// module1.js
export default class Module1{
testFunction(){
return 2
}
}
// module2.js
import Module1 from './module1';
const module1 = new Module1();
export default module1.testFunction();
// test.js
jest.mock('./module1',()=>{ });
import module2 from './module2';
describe('test',()=>{
it('description', ()=>{
expect(module2).toBe(2)
})
});
Environment
React Native Environment Info:
System:
OS: macOS 10.14.1
CPU: (4) x64 Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
Memory: 260.95 MB / 8.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 8.11.3 - /usr/local/bin/node
Yarn: 1.9.4 - /usr/local/bin/yarn
npm: 5.6.0 - /usr/local/bin/npm
Watchman: 4.7.0 - /usr/local/bin/watchman
npmPackages:
react: 16.6.1 => 16.6.1
react-native: 0.57.7 => 0.57.7
npmGlobalPackages:
react-native-cli: 2.0.1
react-native-git-upgrade: 0.2.7
Description
Dependency modules not mocks by
jest.mockReproducible Demo
Expected Behavior
Test failed
Actual Behavior
Test passed