From eb32874fcbf9ee40411160d0f0bd665819d08262 Mon Sep 17 00:00:00 2001 From: 3went2 Date: Fri, 29 Jun 2018 14:50:27 +0800 Subject: [PATCH] fix isTouch bug when emit form.clear() --- src/FormStore/FormStore.js | 7 ++++++- test/demon.test.js | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/FormStore/FormStore.js b/src/FormStore/FormStore.js index 85b6c11..b463d6d 100644 --- a/src/FormStore/FormStore.js +++ b/src/FormStore/FormStore.js @@ -84,5 +84,10 @@ export default class FormStore extends ObjectStore { return pristineValue; }; - @action clear = () => (this.pristineValue = {}); + @action + clear = () => { + const pristineValue = (this.pristineValue = {}); + this.touch(); + return pristineValue; + }; } diff --git a/test/demon.test.js b/test/demon.test.js index 721eb1b..64c1aeb 100644 --- a/test/demon.test.js +++ b/test/demon.test.js @@ -194,6 +194,22 @@ describe('isTouched', () => { expect.objectContaining({ isTouched: false }), ); }); + + test('should `isTouched` be true after form.clear()', () => { + const value = { hello: 'world' }; + const formRef = createRef(); + const children = jest.fn((props) => ); + mount( +
+ {children} +
, + ); + formRef.current.clear(); + expect(children).toHaveBeenCalledWith( + expect.any(Object), + expect.objectContaining({ isTouched: true }), + ); + }); }); describe('isValid', () => {