ProtectedconstructorProvide the TechDocs page path at which the Addon is rendered (e.g. the part of the path after the entity namespace/kind/name).
Return a fully configured and mocked TechDocs reader page within a test App instance, using the given Addon(s).
Render the Addon within a fully configured and mocked TechDocs reader.
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.
Provide mock API implementations if your Addon expects any.
Provide mock HTML if your Addon expects it in the shadow DOM.
Provide a mock entity if your Addon needs it. This also controls the base path at which the Addon is rendered.
Provide mock techdocs_metadata.json values if your Addon needs it.
StaticbuildGet a TechDocsAddonTester instance for a given set of Addons.
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).
Example