Skip to content

Instantly share code, notes, and snippets.

@jergason
Created April 23, 2015 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jergason/128cc2a0f24c6c7c97a6 to your computer and use it in GitHub Desktop.
Save jergason/128cc2a0f24c6c7c97a6 to your computer and use it in GitHub Desktop.
testing react stuff without pulling out my hair
var React = require('react/addons')
var TestUtils = React.addons.TestUtils
var Typeahead = require('../typeahead')
describe('Typeahead', function() {
it('displays a list of items when onChange returns them', function() {
function onChange(text) {
return ['foo','bar','baz']
}
var type = <Typeahead onChange={onChange} />
var container = TestUtils.renderIntoDocument(type)
var input = TestUtils.findRenderedDOMComponentWithTag(container, 'input')
TestUtils.Simulate.change(input, {target: {value: 'f'}})
// If I don't wrap this in a setTimeout, TestUtils.scryDenderedDOMComponentsWithTag returns an empty array.
// I assume this means React hasn't had time to update the DOM yet.
setTimeout(function() {
var buttons = TestUtils.scryRenderedDOMComponentsWithTag('button', container)
expect(buttons.length).toBe(3)
}, 300)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment