Skip to content

Dependency module not mocks by jest.mock #22574

@leerman

Description

@leerman

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.mock

Reproducible Demo

//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)
    })
});

Expected Behavior

Test failed

Actual Behavior

Test passed

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions