diff --git a/packages/uniforms/__tests__/AutoForm.tsx b/packages/uniforms/__tests__/AutoForm.tsx index dc51d45ea..999361008 100644 --- a/packages/uniforms/__tests__/AutoForm.tsx +++ b/packages/uniforms/__tests__/AutoForm.tsx @@ -51,6 +51,22 @@ describe('AutoForm', () => { expect(onChangeModel).toHaveBeenCalledTimes(1); expect(onChangeModel).toHaveBeenLastCalledWith({ a: '2' }); }); + + it('updates `changed` and `changedMap`', () => { + // FIXME: AutoForm is not a valid Component. + const wrapper = mount(); + + const context1 = wrapper.instance().getContext(); + expect(context1).toHaveProperty('changed', false); + expect(context1).toHaveProperty('changedMap', {}); + + wrapper.instance().getContext().onChange('a', '2'); + + const context2 = wrapper.instance().getContext(); + expect(context2).toHaveProperty('changed', true); + expect(context2).toHaveProperty('changedMap.a'); + expect(context2.changedMap.a).toBeTruthy(); + }); }); describe('when rendered', () => { diff --git a/packages/uniforms/src/AutoForm.tsx b/packages/uniforms/src/AutoForm.tsx index f88237b57..b15f4fad7 100644 --- a/packages/uniforms/src/AutoForm.tsx +++ b/packages/uniforms/src/AutoForm.tsx @@ -58,10 +58,10 @@ export function Auto(Base: Base) { } onChange(key: string, value: any) { + super.onChange(key, value); this.setState( state => ({ model: setWith(clone(state.model), key, value, clone) }), () => { - super.onChange(key, value); if (this.props.onChangeModel) this.props.onChangeModel(this.state.model); },