Created
July 26, 2018 23:54
-
-
Save ThaddeusJiang/d1fc01df1555f93a4657330b1129ff0e to your computer and use it in GitHub Desktop.
jest mock import from, mock module(模块)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// step1: 使用 jest.mock | |
import {navigationEnabled, guidanceEnabled} from '../../../magic/index' | |
jest.mock('../../../magic/index', () => ({ | |
navigationEnabled: jest.fn(), | |
guidanceEnabled: jest.fn() | |
})); | |
// step2: 使用 mockImplementationi | |
navigationEnabled.mockImplementation(()=> true) | |
//or | |
navigationEnabled.mockReturnValueOnce(true); | |
// step3: mock 情况 | |
navigationEnabled.mockImplementation(()=> false) | |
//or | |
navigationEnabled.mockReturnValueOnce(false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment