Skip to content

Commit

Permalink
fix isTouch bug when emit form.clear()
Browse files Browse the repository at this point in the history
  • Loading branch information
Cap32 committed Jun 29, 2018
1 parent ceb38b4 commit eb32874
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/FormStore/FormStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}
16 changes: 16 additions & 0 deletions test/demon.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => <input {...props} />);
mount(
<Form value={value} ref={formRef}>
<Demon forwardedProps={{ name: 'hello' }}>{children}</Demon>
</Form>,
);
formRef.current.clear();
expect(children).toHaveBeenCalledWith(
expect.any(Object),
expect.objectContaining({ isTouched: true }),
);
});
});

describe('isValid', () => {
Expand Down

0 comments on commit eb32874

Please sign in to comment.