From 289f0f262ec37d3d5d6a1009f3ef9f44f45cab34 Mon Sep 17 00:00:00 2001 From: Justin Schroeder Date: Wed, 11 Mar 2020 22:01:18 -0400 Subject: [PATCH] Adds tests for new submit error behavior --- src/FormulateInput.vue | 2 +- test/unit/FormulateInput.test.js | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/FormulateInput.vue b/src/FormulateInput.vue index 07fa702..9f567b3 100644 --- a/src/FormulateInput.vue +++ b/src/FormulateInput.vue @@ -139,7 +139,7 @@ export default { type: String, default: 'blur', validator: function (value) { - return ['blur', 'live'].includes(value) + return ['blur', 'live', 'submit'].includes(value) } }, showErrors: { diff --git a/test/unit/FormulateInput.test.js b/test/unit/FormulateInput.test.js index 3ae6479..562d592 100644 --- a/test/unit/FormulateInput.test.js +++ b/test/unit/FormulateInput.test.js @@ -2,6 +2,7 @@ import Vue from 'vue' import flushPromises from 'flush-promises' import { mount } from '@vue/test-utils' import Formulate from '@/Formulate.js' +import FormulateForm from '@/FormulateForm.vue' import FormulateInput from '@/FormulateInput.vue' import FormulateInputBox from '@/inputs/FormulateInputBox.vue' @@ -117,4 +118,27 @@ describe('FormulateInput', () => { await flushPromises() expect(wrapper.contains(FormulateInputBox)).toBe(true) }) + + it('doesnt show errors on blur when set error-behavior is submit', async () => { + const wrapper = mount(FormulateInput, { propsData: { + type: 'special', + validation: 'required', + errorBehavior: 'submit', + } }) + wrapper.find('input').trigger('input') + wrapper.find('input').trigger('blur') + await flushPromises() + expect(wrapper.find('.formulate-input-errors').exists()).toBe(false) + }) + + it('displays errors when error-behavior is submit and form is submitted', async () => { + const wrapper = mount(FormulateForm, { + slots: { + default: `` + } + }) + wrapper.trigger('submit') + await flushPromises() + expect(wrapper.find('.formulate-input-errors').exists()).toBe(true) + }) })