I'm trying to call the close()
method in my Test
component, but it only gets fired when clicking outside the div
that the directive is on. What should I do in my test to make sure that that method gets fired? I'm using the v-click-outside
npm package in my component.
Component
<script>
import vClickOutside from 'v-click-outside';
export default {
name: 'Test',
directives: {
vClickOutside,
},
data: () => ({
isOpen: false,
}),
methods: {
close() {
this.isOpen = false;
},
};
</script>
<template>
<div
v-click-outside="close"
class="test-class"
>
<OtherComponent />
</div>
</template>
This is my test file.
const clickOutsidelDirective = jest.fn();
describe('Test.vue', () => {
const wrapper = shallowMount(Component, {
directives: {
clickOutside: clickOutsidelDirective,
},
});
wrapper.find('.test-class').trigger('click');
//not sure what i have to do to mock the close() function
//This doesn't get called
expect(clickOutsidelDirective).toHaveBeenCalled();
}