Skip to main content

renderWithEffects()

Home > @backstage/test-utils > renderWithEffects

Simplifies rendering of async components in by taking care of the wrapping inside act

Signature:

function renderWithEffects(nodes: ReactElement, options?: Pick<RenderOptions, 'wrapper'> & LegacyRootOption): Promise<RenderResult>;

Parameters

Parameter

Type

Description

nodes

ReactElement

options

Pick<RenderOptions, 'wrapper'> & LegacyRootOption

(Optional)

**Returns:**

Promise<RenderResult>

Remarks

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. https://github.com/testing-library/react-testing-library/issues/281 https://github.com/facebook/react/pull/14853