import { shallowMount } from '@vue/test-utils';
test('should render with render function', () => {
const wrapper = shallowMount({
render() {
return
calls.push(4)}
hook-insert={() => calls.push(2)}
/>
);
},
});
expect(wrapper.attributes('id')).toBe('hehe');
expect(wrapper.attributes('href')).toBe('huhu');
expect(wrapper.text()).toBe('2');
expect(wrapper.classes()).toEqual(expect.arrayContaining(['a', 'b', 'c']));
await wrapper.trigger('click');
expect(calls).toEqual(expect.arrayContaining([3, 4]));
});
test('directive', () => {
const calls = [];
const customDirective = {
mounted() {
calls.push(1);
},
};
const wrapper = shallowMount(({
directives: { custom: customDirective },
setup() {
return () => (
);
},
}));
const node = wrapper.vm.$.subTree;
expect(calls).toEqual(expect.arrayContaining([1]));
expect(node.dirs).toHaveLength(1);
});