Created
April 23, 2015 16:13
-
-
Save jergason/128cc2a0f24c6c7c97a6 to your computer and use it in GitHub Desktop.
testing react stuff without pulling out my hair
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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