From ce6a89c895652e62c5e9a4935c9b9ca2bf52d82c Mon Sep 17 00:00:00 2001 From: Thomas Rutten <30386411+T-Motion@users.noreply.github.com> Date: Wed, 19 Feb 2020 15:47:49 +0100 Subject: [PATCH] fix(validate): reset validation result on validators change (#565) --- packages/validate/src/ValidateMixin.js | 2 +- .../test-suites/ValidateMixin.suite.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/validate/src/ValidateMixin.js b/packages/validate/src/ValidateMixin.js index 82c5cb91e..8252ab75f 100644 --- a/packages/validate/src/ValidateMixin.js +++ b/packages/validate/src/ValidateMixin.js @@ -200,7 +200,7 @@ export const ValidateMixin = dedupeMixin( if (name === 'validators') { // trigger validation (ideally only for the new or changed validator) this.__setupValidators(); - this.validate(); + this.validate({ clearCurrentResult: true }); } else if (name === 'modelValue') { this.validate({ clearCurrentResult: true }); } diff --git a/packages/validate/test-suites/ValidateMixin.suite.js b/packages/validate/test-suites/ValidateMixin.suite.js index 03f1d95a0..8b965b548 100644 --- a/packages/validate/test-suites/ValidateMixin.suite.js +++ b/packages/validate/test-suites/ValidateMixin.suite.js @@ -812,6 +812,25 @@ export function runValidateMixinSuite(customConfig) { expect(el.validationStates.error).to.eql({}); }); + it('clears current validation results when validators array updated', async () => { + const validators = [new Required()]; + const el = await fixture(html` + <${tag} + .validators=${validators} + >${lightDom} + `); + expect(el.hasFeedbackFor).to.deep.equal(['error']); + expect(el.validationStates.error).to.eql({ Required: true }); + + el.validators = []; + expect(el.hasFeedbackFor).to.not.deep.equal(['error']); + expect(el.validationStates.error).to.eql({}); + + el.validators = [new Required()]; + expect(el.hasFeedbackFor).to.deep.equal(['error']); + expect(el.validationStates.error).to.not.eql({}); + }); + describe('Events', () => { it('fires "showsFeedbackForChanged" event async after feedbackData got synced to feedbackElement', async () => { const spy = sinon.spy();