From 872fbac679ed97884eae83afb9e2c1c3d62ce923 Mon Sep 17 00:00:00 2001 From: Adam Berecz Date: Wed, 18 Oct 2023 10:49:06 +0200 Subject: [PATCH] test: unmound, findAllComp test helpers --- tests/unit/helpers/vue2.js | 19 +++++++++++++++++-- tests/unit/helpers/vue3.js | 19 +++++++++++++++++-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/tests/unit/helpers/vue2.js b/tests/unit/helpers/vue2.js index 7fb0b5d..ed8eca7 100644 --- a/tests/unit/helpers/vue2.js +++ b/tests/unit/helpers/vue2.js @@ -1,7 +1,7 @@ import { mount, createLocalVue } from '@vue/test-utils' import Multiselect from './../../../dist/multiselect.vue2' -export const createSelect = (props = {}, options = {}) => { +export const createSelect = (props = {}, options = {}, returnWrapper = false) => { const localVue = createLocalVue() localVue.use({ @@ -42,13 +42,19 @@ export const createSelect = (props = {}, options = {}) => { } }, config) - return wrapper.findAllComponents({ name: 'Multiselect' }).at(0) + return returnWrapper + ? wrapper + : wrapper.findAllComponents({ name: 'Multiselect' }).at(0) } export const destroy = (wrapper) => { wrapper.destroy() } +export const unmount = (wrapper) => { + wrapper.destroy() +} + const keyEvent = (event, wrapper, key) => { if (typeof key === 'object') { wrapper.trigger(event, key) @@ -100,6 +106,15 @@ export const findAll = (parent, query) => { } } +export const findAllComponents = (parent, query) => { + let res = parent.findAllComponents(query) + + return { + at: (i) => { return res.at(i) }, + length: res.length, + } +} + export const getValue = (select) => { return select.vm.value } diff --git a/tests/unit/helpers/vue3.js b/tests/unit/helpers/vue3.js index 9ac83ca..be8b83a 100644 --- a/tests/unit/helpers/vue3.js +++ b/tests/unit/helpers/vue3.js @@ -1,7 +1,7 @@ import { mount } from '@vue/test-utils' import Multiselect from './../../../src/Multiselect.vue' -export const createSelect = (props = {}, options = {}) => { +export const createSelect = (props = {}, options = {}, returnWrapper = false) => { let config = {} document.body.innerHTML = ` @@ -34,11 +34,17 @@ export const createSelect = (props = {}, options = {}) => { } }, config) - return wrapper.findAllComponents({ name: 'Multiselect' })[0] + return returnWrapper + ? wrapper + : wrapper.findAllComponents({ name: 'Multiselect' })[0] } export const destroy = (wrapper) => {} +export const unmount = (wrapper) => { + wrapper.unmount() +} + const keyEvent = (event, wrapper, key) => { let triggerKey = '' @@ -100,6 +106,15 @@ export const findAll = (parent, query) => { } } +export const findAllComponents = (parent, query) => { + let res = parent.findAllComponents(query) + + return { + at: (i) => { return res[i] }, + length: res.length, + } +} + export const getValue = (select) => { return select.vm.modelValue }