From 98b5c0935d1cf8e5d89d145d60efaef51df496bc Mon Sep 17 00:00:00 2001 From: Zaytsev Kirill Date: Wed, 28 Oct 2020 21:25:20 +0300 Subject: [PATCH] test: Restored remaining tests for form --- test/unit/FormularioForm.test.js | 67 +++++++++++++++----------------- 1 file changed, 31 insertions(+), 36 deletions(-) diff --git a/test/unit/FormularioForm.test.js b/test/unit/FormularioForm.test.js index e644f02..85106ac 100644 --- a/test/unit/FormularioForm.test.js +++ b/test/unit/FormularioForm.test.js @@ -48,7 +48,7 @@ describe('FormularioForm', () => { ` } }) - expect(wrapper.vm.registry.keys()).toEqual(['sub1', 'sub2']) + expect(wrapper.vm['registry'].keys()).toEqual(['sub1', 'sub2']) }) it('Removes subcomponents from the registry', async () => { @@ -62,10 +62,10 @@ describe('FormularioForm', () => { ` }) await flushPromises() - expect(wrapper.findComponent(FormularioForm).vm.registry.keys()).toEqual(['sub1', 'sub2']) + expect(wrapper.findComponent(FormularioForm).vm['registry'].keys()).toEqual(['sub1', 'sub2']) wrapper.setData({ active: false }) await flushPromises() - expect(wrapper.findComponent(FormularioForm).vm.registry.keys()).toEqual(['sub2']) + expect(wrapper.findComponent(FormularioForm).vm['registry'].keys()).toEqual(['sub2']) }) it('Getting nested fields from registry', async () => { @@ -347,10 +347,21 @@ describe('FormularioForm', () => { it('Emits correct validation event on entry', async () => { const wrapper = mount(FormularioForm, { slots: { default: ` - - + + - + ` } }) wrapper.find('input[type="text"]').setValue('bar') @@ -361,37 +372,21 @@ describe('FormularioForm', () => { expect(wrapper.emitted('validation')).toBeTruthy() expect(wrapper.emitted('validation').length).toBe(1) expect(wrapper.emitted('validation')[0][0]).toEqual({ - name: 'foo', - violations: [ expect.any(Object) ], // @TODO: Check object structure + name: 'firstField', + violations: [ { + rule: expect.any(String), + args: ['foo'], + context: { + value: 'bar', + formValues: expect.any(Object), + name: 'firstField', + }, + message: expect.any(String), + } ], }) }) - return - - it('Removes field data when that field is de-registered', async () => { - const wrapper = mount({ - data: () => ({ values: {} }), - template: ` - - - - - - - `, - }) - - await flushPromises() - - wrapper.find('input[type="text"]').setValue('bar') - - await flushPromises() - - expect(wrapper.findComponent(FormularioForm).vm.proxy).toEqual({ foo: 'bar' }) - expect(wrapper.vm['values']).toEqual({ foo: 'bar' }) - }) - - it('Allows resetting a form, hiding validation and clearing inputs.', async () => { + it('Allows resetting a form, wiping validation.', async () => { const wrapper = mount({ data: () => ({ values: {} }), template: ` @@ -411,6 +406,7 @@ describe('FormularioForm', () => { }) const password = wrapper.find('input[type="password"]') + password.setValue('foo') password.trigger('blur') @@ -422,10 +418,9 @@ describe('FormularioForm', () => { // First make sure we caught the errors expect(Object.keys(wrapper.vm.$refs.form.mergedFieldErrors).length).toBe(1) wrapper.vm.$refs.form.resetValidation() - wrapper.vm.$refs.form.setValues({ }) await flushPromises() + expect(Object.keys(wrapper.vm.$refs.form.mergedFieldErrors).length).toBe(0) - expect(wrapper.vm['values']).toEqual({}) }) })