Properties

children: ElementExplorer[]

The child elements of the rendered element

The rendered element data, which is the string content in the case of a base element

parent: null | ElementExplorer

the parent element of the rendered element

props: Record<string, unknown>

The props object of the rendered element

type: null | string

The type of the rendered element

Accessors

Methods

  • Find an element by its className

    Parameters

    • className: string

    Returns ElementExplorer[]

    An array of ElementExplorer instances that match the className

    Example

    const el = shallow(
    <div><button className="test-button">Test Button</button></div>
    );
    const explorer = el.instance;
    const buttons = explorer.findByClassName('test-button');
  • Find an element by its data-testid attribute

    Parameters

    • testId: string

    Returns ElementExplorer[]

    An array of ElementExplorer instances that match the testId

    Example

    const el = shallow(
    <div data-testid="parent"><div data-testid="child"></div></div>
    );
    const explorer = el.instance;
    const childElements = explorer.findByTestId("child");
  • Find an element by its type

    Parameters

    • type: string | {
          name: string;
      }

    Returns ElementExplorer[]

    An array of ElementExplorer instances that match the type

    Example

    const el = shallow(
    <div><button>Test Button</button></div>
    );
    const explorer = el.instance;
    const buttons = explorer.findByType('button');
  • Check if the element matches the provided element

    Parameters

    Returns boolean

    A boolean indicating if the element matches the provided element

    Example

    const el = shallow(
    <div><button>Test Button</button></div>
    );
    const explorer = el.instance;
    const button = explorer.findByType('button')[0];
    const matches = button.matches(shallow(<button>Test Button</button>));
    expect(matches).toBe(true);

Generated using TypeDoc