Last active
March 26, 2019 17:01
-
-
Save dasDaniel/d4fb8f0eb6f36acdbe7b1ce66c034949 to your computer and use it in GitHub Desktop.
helper functions for vue-test-utils
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
function withWrapperArray(wrapperArray) { | |
return { | |
childSelectorHasText: (selector, str) => wrapperArray.filter(i => i.find(selector).text().match(str)), | |
hasText: (str) => wrapperArray.filter(i => i.text().match(str)), | |
areVisible: () => wrapperArray.wrappers.filter(w => w.isVisible()).length, | |
areHidden: () => wrapperArray.wrappers.filter(w => !w.isVisible()).length, | |
areAllVisible: () => wrapperArray.wrappers.every(w => w.isVisible()), | |
areAllHidden: () => wrapperArray.wrappers.every(w => !w.isVisible()), | |
} | |
} |
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
// find first element that that has class name `.filter__name` with a textvalue of `Vehicles` | |
withWrapperArray(wrapper.findAll('.filter__name')).hasText('Vehicles').at(0); | |
// find an element that has a child with matching text content | |
withWrapperArray(wrapper.findAll('.filter')).childSelectorHasText('label', 'Saab').at(0) | |
// get the input that's a sibling of the matched label | |
withWrapperArray(wrapper.findAll('.filter')).childSelectorHasText('label', 'Saab').at(0).find('input') | |
// are all matched elements hidden? | |
expect(withWrapperArray(wrapper.findAll('.filter')).areAllHidden()).toBeTruthy(); | |
// are all matched elements visible? | |
expect(withWrapperArray(wrapper.findAll('.filter')).areAllVisible()).toBeTruthy(); | |
// are some matched elements hidden? | |
expect(withWrapperArray(wrapper.findAll('.filter')).areHidden()).toBeTruthy(); | |
// are some matched elements visible? | |
expect(withWrapperArray(wrapper.findAll('.filter')).areVisible()).toBeTruthy(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment