diff --git a/test/unit/FormularioForm.test.js b/test/unit/FormularioForm.test.js
index 015239b..deb37dc 100644
--- a/test/unit/FormularioForm.test.js
+++ b/test/unit/FormularioForm.test.js
@@ -43,8 +43,8 @@ describe('FormularioForm', () => {
propsData: { formularioValue: {} },
slots: {
default: `
-
-
+
+
`
}
})
@@ -56,8 +56,8 @@ describe('FormularioForm', () => {
data: () => ({ active: true }),
template: `
-
-
+
+
`
})
@@ -152,7 +152,7 @@ describe('FormularioForm', () => {
}),
template: `
-
+
`
})
@@ -164,13 +164,13 @@ describe('FormularioForm', () => {
it('updates calls setFieldValue on form when a field contains a populated v-model on registration', () => {
const wrapper = mount(FormularioForm, {
propsData: {
- formularioValue: { testinput: '123' }
+ formularioValue: { test: '123' }
},
slots: {
- default: ''
+ default: ''
}
})
- expect(wrapper.emitted().input[wrapper.emitted().input.length - 1]).toEqual([{ testinput: 'override-data' }])
+ expect(wrapper.emitted().input[wrapper.emitted().input.length - 1]).toEqual([{ test: 'override-data' }])
})
it('updates an inputs value when the form v-model is modified', async () => {
@@ -190,9 +190,9 @@ describe('FormularioForm', () => {
expect(wrapper.find('input[type="text"]').element['value']).toBe('1234')
})
- it('resolves hasValidationErrors to true', async () => {
+ it('Resolves hasValidationErrors to true', async () => {
const wrapper = mount(FormularioForm, {
- slots: { default: '' }
+ slots: { default: '' }
})
wrapper.find('form').trigger('submit')
await flushPromises()
@@ -205,7 +205,7 @@ describe('FormularioForm', () => {
it('Resolves submitted form values to an object', async () => {
const wrapper = mount(FormularioForm, {
- slots: { default: '' }
+ slots: { default: '' }
})
wrapper.find('form').trigger('submit')
await flushPromises()
@@ -269,7 +269,7 @@ describe('FormularioForm', () => {
slots: {
default: `
-
+
`
},
})
@@ -286,7 +286,7 @@ describe('FormularioForm', () => {
slots: {
default: `
-
+
`
},
})
@@ -308,81 +308,75 @@ describe('FormularioForm', () => {
expect(wrapper.vm.mergedFieldErrors.inputB.length).toBe(2)
})
- return
+ it('Emits correct validation event when no errors', async () => {
+ const wrapper = mount(FormularioForm, {
+ slots: {
+ default: `
+
+
+
+
+ `,
+ }
+ })
+ wrapper.find('input[type="text"]').setValue('foo')
+ wrapper.find('input[type="text"]').trigger('blur')
+
+ await flushPromises()
+
+ expect(wrapper.emitted('validation')).toBeTruthy()
+ expect(wrapper.emitted('validation').length).toBe(1)
+ expect(wrapper.emitted('validation')[0][0]).toEqual({
+ name: 'foo',
+ errors: [],
+ })
+ })
it('Emits correct validation event on entry', async () => {
const wrapper = mount(FormularioForm, {
slots: { default: `
-
-
+
+
-
+
` }
})
wrapper.find('input[type="text"]').setValue('bar')
+ wrapper.find('input[type="text"]').trigger('blur')
await flushPromises()
- const errorObjects = wrapper.emitted('validation')
- // There should be 3 events, both inputs mounting, and the value being set removing required on testinput
- expect(errorObjects.length).toBe(3)
- // this should be the event from the setValue()
- const errorObject = errorObjects[2][0]
- expect(errorObject).toEqual({
+ expect(wrapper.emitted('validation')).toBeTruthy()
+ expect(wrapper.emitted('validation').length).toBe(1)
+ expect(wrapper.emitted('validation')[0][0]).toEqual({
name: 'foo',
- errors: [
- expect.any(String)
- ],
- hasErrors: true
+ errors: [ expect.any(Object) ], // @TODO: Check object structure
})
})
- it('emits correct validation event when no errors', async () => {
- const wrapper = mount(FormularioForm, {
- slots: { default: `
-
-
-
-
-
-
- ` }
- })
- wrapper.find('input[type="text"]').setValue('bar')
- await flushPromises()
- const errorObjects = wrapper.emitted('validation')
- expect(errorObjects.length).toBe(3)
- const errorObject = errorObjects[2][0]
- expect(errorObject).toEqual({
- name: 'testinput',
- errors: [],
- hasErrors: false
- })
- })
+ return
- it('removes field data when that field is de-registered', async () => {
+ it('Removes field data when that field is de-registered', async () => {
const wrapper = mount({
+ data: () => ({ values: {} }),
template: `
-
-
-
+
+
+
-
+
`,
- data () {
- return {
- formData: {}
- }
- }
})
+
await flushPromises()
+
wrapper.find('input[type="text"]').setValue('bar')
+
await flushPromises()
+
expect(wrapper.findComponent(FormularioForm).vm.proxy).toEqual({ foo: 'bar' })
- expect(wrapper.vm.formData).toEqual({ foo: 'bar' })
+ expect(wrapper.vm['values']).toEqual({ foo: 'bar' })
})
it('Allows resetting a form, hiding validation and clearing inputs.', async () => {