Skip to content

Commit

Permalink
test: unmound, findAllComp test helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
adamberecz committed Oct 18, 2023
1 parent 94f3efa commit 872fbac
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
19 changes: 17 additions & 2 deletions tests/unit/helpers/vue2.js
Original file line number Diff line number Diff line change
@@ -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({
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down
19 changes: 17 additions & 2 deletions tests/unit/helpers/vue3.js
Original file line number Diff line number Diff line change
@@ -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 = `
Expand Down Expand Up @@ -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 = ''

Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 872fbac

Please sign in to comment.