I donβt have unit test HTML at all (I believe that if unit tests of React are tested, the generated HTML is good, plus I intend to conduct an integration test with selenium to test HTML anyway), but I check that the component generates the correct virtual DOM.
I have a similar component, and the way I test autofill items is as follows.
var testAutoCompleteItems = [{ display: 'test 1', value: 1 }, { display: 'test 2', value: 2 }, { display: 'test 3', value: 3 }]; //... it('should set items based on pass getData property', function(done) { Fiber(function() { testGlobals.component = React.render(<ExtendText onChange={testHelper.noop} getData={getData} />, div); var input = TestUtils.findRenderedDOMComponentWithClass(testGlobals.component, 'extend-text__display-input'); TestUtils.Simulate.focus(input); testHelper.sleep(5); var autoCompleteContainer = TestUtils.findRenderedDOMComponentWithClass(testGlobals.component, 'extend-text__auto-complete-container'); var autoCompleteItems = TestUtils.scryRenderedDOMComponentsWithTag(autoCompleteContainer, 'li'); //make sure elements are correct autoCompleteItems.forEach(function(item, key) { expect(item.props['data-key']).to.equal(key); expect(item.props.children).to.equal(testAutoCompleteItems[key].display); }); //make sure there is the correct number of elements expect(autoCompleteItems.length).to.equal(3); done(); }).run(); });
source share