From 9155964f0f3a89c0f8869c759fcb939eef997c37 Mon Sep 17 00:00:00 2001 From: Erik Rasmussen Date: Fri, 1 Dec 2017 12:54:40 +0100 Subject: [PATCH] Avoid api prop bleed-through --- src/Field.js | 2 ++ src/Field.test.js | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/src/Field.js b/src/Field.js index d4db8a73..1901e6c5 100644 --- a/src/Field.js +++ b/src/Field.js @@ -104,6 +104,8 @@ export default class Field extends React.PureComponent { component, children, allowNull, + subscription, + validate, value: _value, ...rest } = this.props diff --git a/src/Field.test.js b/src/Field.test.js index 764d317e..dd88a370 100644 --- a/src/Field.test.js +++ b/src/Field.test.js @@ -237,6 +237,43 @@ describe('Field', () => { expect(render.mock.calls[2][0].values.foo).toBe(null) }) + it('should not let validate prop bleed through', () => { + const input = jest.fn(({ input }) => ) + const required = value => (value ? undefined : 'Required') + + TestUtils.renderIntoDocument( +
+ {() => ( + + + + )} + + ) + + expect(input).toHaveBeenCalled() + expect(input).toHaveBeenCalledTimes(1) + expect(input.mock.calls[0][0].validate).toBeUndefined() + }) + + it('should not let subscription prop bleed through', () => { + const input = jest.fn(({ input }) => ) + + TestUtils.renderIntoDocument( +
+ {() => ( + + + + )} + + ) + + expect(input).toHaveBeenCalled() + expect(input).toHaveBeenCalledTimes(1) + expect(input.mock.calls[0][0].subscription).toBeUndefined() + }) + it('should allow changing field-level validation function', () => { const input = jest.fn(({ input }) => ) const required = value => (value ? undefined : 'Required')