I am building some basic tests for my components in react. Currently I have a header rendered with a prop that is passed to it. the test is super simple and passes. But what about negative testing?
I would like to now pass an array to this header and see it fail. But how to I test for that?
I have currently got my expects statement like this
expect(ReactDOM.findDOMNode(h1).textContent).toEqual("A title");
How would I say
expect(Element).toFailOn(incorrect type)
btw im using
Joseph Lloyd
JavaScript Developer
To answer my own question
There are some functions that are in React Util that you can use to search for elements so in my case it was like this
let component = TestUtils.renderIntoDocument( <Heading /> ); let h1 = TestUtils.scryRenderedDOMComponentsWithTag( component, 'h1' ); expect(h1.length).toEqual(0);since no arguments are passed to the Heading then no h1 elements should be rendered on the DOM