1
0
mirror of synced 2024-11-22 21:36:04 +03:00
vue-formulario/test/unit/Formulario.test.js

57 lines
1.7 KiB
JavaScript

import { createLocalVue, mount } from '@vue/test-utils'
import Formulario from '@/Formulario.ts'
import plugin from '@/index.ts'
describe('Formulario', () => {
it('installs on vue instance', () => {
const localVue = createLocalVue()
localVue.use(plugin)
expect(localVue.component('FormularioField')).toBeTruthy()
expect(localVue.component('FormularioFieldGroup')).toBeTruthy()
expect(localVue.component('FormularioForm')).toBeTruthy()
const wrapper = mount({ render: h => h('div'), }, { localVue })
expect(wrapper.vm.$formulario).toBeInstanceOf(Formulario)
})
it ('pushes Formulario instance to child a component', () => {
const localVue = createLocalVue()
localVue.use(plugin)
const ChildComponent = localVue.component('ChildComponent', {
render: h => h('div'),
})
const parent = mount({
render: h => h('div', [h('ChildComponent')]),
}, { localVue })
const child = parent.findComponent(ChildComponent)
expect(parent.vm.$formulario === child.vm.$formulario).toBe(true)
})
it ('does not push Formulario instance to a child component, if it has its own', () => {
const localVue = createLocalVue()
localVue.use(plugin)
// noinspection JSCheckFunctionSignatures
const ChildComponent = localVue.component('ChildComponent', {
formulario: () => new Formulario(),
render: h => h('div'),
})
const parent = mount({
render: h => h('div', [h('ChildComponent')]),
}, { localVue })
const child = parent.findComponent(ChildComponent)
expect(parent.vm.$formulario === child.vm.$formulario).toBe(false)
})
})