1
0
mirror of synced 2024-12-01 17:46:07 +03:00
vue-formulario/test/unit/Formulario.test.js

63 lines
1.8 KiB
JavaScript
Raw Normal View History

import { createLocalVue, mount } from '@vue/test-utils'
import Formulario from '@/Formulario.ts'
import plugin from '@/index.ts'
2020-05-22 14:22:16 +03:00
describe('Formulario', () => {
it('Installs on vue instance', () => {
const localVue = createLocalVue()
localVue.use(plugin)
expect(localVue.component('FormularioForm')).toBeTruthy()
expect(localVue.component('FormularioGrouping')).toBeTruthy()
expect(localVue.component('FormularioInput')).toBeTruthy()
const wrapper = mount({ template: '<div />', }, { localVue })
expect(wrapper.vm.$formulario).toBeInstanceOf(Formulario)
})
it ('Pushes Formulario instance to child a component', () => {
const localVue = createLocalVue()
localVue.use(plugin)
localVue.component('TestComponent', {
render (h) {
return h('div')
}
})
const wrapper = mount({
render (h) {
return h('div', [h('TestComponent', { ref: 'test' })])
},
}, { localVue })
expect(wrapper.vm.$formulario === wrapper.vm.$refs.test.$formulario).toBe(true)
})
it ('Does not pushes Formulario instance to a child component, if it has its own', () => {
const localVue = createLocalVue()
localVue.use(plugin)
// noinspection JSCheckFunctionSignatures
localVue.component('TestComponent', {
formulario () {
return new Formulario()
},
render (h) {
return h('div')
},
})
const wrapper = mount({
render (h) {
return h('div', [h('TestComponent', { ref: 'test' })])
},
}, { localVue })
expect(wrapper.vm.$formulario === wrapper.vm.$refs.test.$formulario).toBe(false)
2020-05-22 14:22:16 +03:00
})
})