Skip to content

Commit

Permalink
test(Input): add onChange(e, props) test
Browse files Browse the repository at this point in the history
  • Loading branch information
levithomason committed Nov 13, 2016
1 parent 8704dd4 commit 4c3f744
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions test/specs/elements/Input/Input-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import cx from 'classnames'
import _ from 'lodash'
import React from 'react'
import { sandbox } from 'test/utils'

import Input, { htmlInputPropNames } from 'src/elements/Input/Input'
import * as common from 'test/specs/commonTests'
Expand Down Expand Up @@ -56,10 +57,33 @@ describe('Input', () => {
describe('input props', () => {
htmlInputPropNames.forEach(propName => {
it(`passes \`${propName}\` to the <input>`, () => {
shallow(<Input {...{ [propName]: 'foo' }} />)
const propValue = propName === 'onChange' ? (() => null) : 'foo'
const wrapper = shallow(<Input {...{ [propName]: propValue }} />)

// account for overloading the onChange prop
const expectedValue = propName === 'onChange'
? wrapper.instance().handleChange
: propValue

wrapper
.find('input')
.should.have.prop(propName, 'foo')
.should.have.prop(propName, expectedValue)
})
})
})

describe('onChange', () => {
it('is called with (event, props) on change', () => {
const spy = sandbox.spy()
const event = { fake: 'event' }
const props = { 'data-foo': 'bar', onChange: spy }

const wrapper = shallow(<Input {...props} />)

wrapper.find('input').simulate('change', event)

spy.should.have.been.calledOnce()
spy.should.have.been.calledWithMatch(event, props)
})
})
})

0 comments on commit 4c3f744

Please sign in to comment.