Backstage
    Preparing search index...

    Utility class for rendering TechDocs Addons end-to-end within the TechDocs reader page, with a set of givens (e.g. page DOM, metadata, etc).

    const { getByText } = await TechDocsAddonTester.buildAddonsInTechDocs([<AnAddon />])
    .withDom(<body>TEST_CONTENT</body>)
    .renderWithEffects();

    expect(getByText('TEST_CONTENT')).toBeInTheDocument();
    Index

    Constructors

    Methods

    • Return a fully configured and mocked TechDocs reader page within a test App instance, using the given Addon(s).

      Returns ReactElement<any, string | JSXElementConstructor<any>>

    • Render the Addon within a fully configured and mocked TechDocs reader.

      Returns Promise<{ shadowRoot: ShadowRoot | null }>

      Note that to make assertions on the shadow dom, add a dependency on the shadow-dom-testing-library package and use its screen as follows:

      import { screen } from 'shadow-dom-testing-library';

      // ... render the addon ...
      await TechDocsAddonTester.buildAddonsInTechDocs([<AnAddon />])
      .withDom(<body>TEST_CONTENT</body>)
      .renderWithEffects();

      expect(screen.getByShadowText('TEST_CONTENT')).toBeInTheDocument();

      For items outside of the shadow dom, you can still use the regular screen from @testing-library/react.

      Components using useEffect to perform an asynchronous action (such as fetch) must be rendered within an async act call to properly get the final state, even with mocked responses. This utility method makes the signature a bit cleaner, since act doesn't return the result of the evaluated function.