Last active
May 19, 2019 18:05
-
-
Save achhunna/7c9876edff249cfd776cc4b0a4970059 to your computer and use it in GitHub Desktop.
Mocking methods
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
// using jest.fn() to mock action and mutation functions | |
beforeEach(() => { | |
actions = { | |
someAction: jest.fn(() => true) | |
}; | |
mutations = { | |
someMutation: jest.fn(() => false) | |
}; | |
state = { | |
key: {} | |
}; | |
store = new Vuex.Store({ | |
actions, | |
mutations, | |
state, | |
}); | |
... | |
}); | |
... | |
// using jest.fn() to mock component method or another other global functions | |
test('clicking search button triggers search()', () => { | |
window.open = jest.fn(); // global function mock to stop actual from executing | |
wrapper.vm.search = jest.fn(); | |
const searchBtn = '.search-btn'; | |
wrapper.find(searchBtn).trigger('click'); | |
expect(wrapper.vm.search).toBeCalled(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment