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);
});

3 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Very interesting and helpful sharing, thank you very much.Street View Online

    ReplyDelete
  3. Using the online service https://topessaybrands.com/review/ewriters-pro-review/ I do all the writing assignments and it helps me a lot in my learning and getting good grades. I, too, do not lose trust from the teachers and my reputation has become much better.

    ReplyDelete

Blogroll

Follow this blog by Email

Popular Posts