This is the child article of ReactTestUtils - Tutorial. In this article, I will explain how to Check Component or Element Type. Here we can verify
Verify DOM Component
General HTML components are DOM Components. It can be verified with isDOMComponent function. Below example finds element with h1 tag. isDOMComponent function returns true
it('Verify Dom Component', function () { var root = TestUtils.renderIntoDocument(<Root/>); var rootElm = TestUtils.findRenderedDOMComponentWithTag(root, 'h1'); expect(TestUtils.isElement(rootElm)).toEqual(false); expect(TestUtils.isDOMComponent(rootElm)).toEqual(true); expect(TestUtils.isCompositeComponent(rootElm)).toEqual(false); });
Verify Composite Component
User defined React element is Composite component. Here SubRoot is user defined React element, It can be verified using isCompositeComponent
it('Verify Composite Type', function () { var root = TestUtils.renderIntoDocument(<Root/>); var rootElm = TestUtils.findRenderedComponentWithType(root, SubRoot); expect(TestUtils.isElement(rootElm)).toEqual(false); expect(TestUtils.isDOMComponent(rootElm)).toEqual(false); expect(TestUtils.isCompositeComponent(rootElm)).toEqual(true); expect(TestUtils.isCompositeComponentWithType(rootElm, SubRoot)).toEqual(true); });
0 comments:
Post a Comment