Last active
July 13, 2020 19:49
-
-
Save thenoseman/7a2f8666b967feccb2bfd107634c5ba4 to your computer and use it in GitHub Desktop.
How to test watchers in vue
This file contains 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
it("calls #loadCities if the zipCode is correct and there are 1+ chars in the field", async () => { | |
// This is how to test watchers: | |
// 1. set the starting data if neccessary | |
wrapper.setData({ searchTermCity: "", address: { zipCode: "12345" } }); | |
// 2. Change the current value | |
wrapper.vm.searchTermCity = "Ha"; | |
// 3. Manually trigger watcher since vue-test-utils doesn't do that anymore:( | |
wrapper.vm._watchers.find(w => w.expression === "searchTermCity").run(); | |
expect(wrapper.vm.loadCities).toHaveBeenCalledWith("Ha"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment