Skip to content

Commit a7d261d

Browse files
authored
Merge pull request #16 from erikras/bleedthru
Avoid api prop bleed-through
2 parents 8b878a0 + 9155964 commit a7d261d

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

src/Field.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ export default class Field extends React.PureComponent<Props, State> {
104104
component,
105105
children,
106106
allowNull,
107+
subscription,
108+
validate,
107109
value: _value,
108110
...rest
109111
} = this.props

src/Field.test.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,43 @@ describe('Field', () => {
237237
expect(render.mock.calls[2][0].values.foo).toBe(null)
238238
})
239239

240+
it('should not let validate prop bleed through', () => {
241+
const input = jest.fn(({ input }) => <input {...input} />)
242+
const required = value => (value ? undefined : 'Required')
243+
244+
TestUtils.renderIntoDocument(
245+
<Form onSubmit={onSubmitMock}>
246+
{() => (
247+
<form>
248+
<Field name="foo" render={input} validate={required} />
249+
</form>
250+
)}
251+
</Form>
252+
)
253+
254+
expect(input).toHaveBeenCalled()
255+
expect(input).toHaveBeenCalledTimes(1)
256+
expect(input.mock.calls[0][0].validate).toBeUndefined()
257+
})
258+
259+
it('should not let subscription prop bleed through', () => {
260+
const input = jest.fn(({ input }) => <input {...input} />)
261+
262+
TestUtils.renderIntoDocument(
263+
<Form onSubmit={onSubmitMock}>
264+
{() => (
265+
<form>
266+
<Field name="foo" render={input} subscription={{ active: true }} />
267+
</form>
268+
)}
269+
</Form>
270+
)
271+
272+
expect(input).toHaveBeenCalled()
273+
expect(input).toHaveBeenCalledTimes(1)
274+
expect(input.mock.calls[0][0].subscription).toBeUndefined()
275+
})
276+
240277
it('should allow changing field-level validation function', () => {
241278
const input = jest.fn(({ input }) => <input {...input} />)
242279
const required = value => (value ? undefined : 'Required')

0 commit comments

Comments
 (0)