Skip to content

Commit

Permalink
Add test for input change events
Browse files Browse the repository at this point in the history
  • Loading branch information
jxnblk committed May 29, 2016
1 parent 171eaa5 commit c02aac1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
"babel-preset-stage-0": "^6.5.0",
"babel-register": "^6.5.2",
"expect": "^1.14.0",
"jsdom": "^9.2.1",
"mocha": "^2.4.5",
"mocha-jsdom": "^1.1.0",
"onchange": "^2.0.0",
"react": "^15.0.1",
"react-addons-test-utils": "^15.0.1",
Expand Down
34 changes: 34 additions & 0 deletions test/Input.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import React from 'react'
import TestUtils from 'react-addons-test-utils'
import expect from 'expect'
import jsdom from 'mocha-jsdom'
import { Input, Label, Base, config } from '../src'

const renderer = TestUtils.createRenderer()
Expand Down Expand Up @@ -185,5 +186,38 @@ describe('Input', () => {
expect(tree.props.style.color).toEqual('tomato')
})
})

describe('events', () => {
jsdom()

context('when change event is fired', () => {
const spy = expect.createSpy()
const render = TestUtils.renderIntoDocument
class Root extends React.Component { render () { return this.props.children } }
let node

before(() => {
tree = render(
<Root>
<Input
name='test'
label='Test'
onChange={spy} />
</Root>
)
node = TestUtils.findRenderedDOMComponentWithTag(tree, 'input')
TestUtils.Simulate.change(node)
})

it('should call the onChange callback', () => {
expect(spy).toHaveBeenCalled()
expect(spy.calls.length).toEqual(1)
})

it('should not call the onChange twice', () => {
expect(spy.calls.length).toNotEqual(2)
})
})
})
})

0 comments on commit c02aac1

Please sign in to comment.