Skip to main content

Module: tests/utils/rendering

Type Aliases

ApiTestProvidersProps

Ƭ ApiTestProvidersProps: PropsWithChildren<{ apolloMocks?: ReadonlyArray<MockedResponse> ; apolloProviderProps?: MockedProviderProps }>

A set of properties that will be passed to Apollo's MockerProvider

Defined in

packages/webapp-libs/webapp-api-client/src/tests/utils/rendering.tsx:16


CustomRenderOptions

Ƭ CustomRenderOptions<Q, Container, BaseElement>: RenderOptions<Q, Container, BaseElement> & WrapperProps

Type parameters

NameType
Qextends Queries = typeof queries
Containerextends Element | DocumentFragment = HTMLElement
BaseElementextends Element | DocumentFragment = Container

Defined in

packages/webapp-libs/webapp-api-client/src/tests/utils/rendering.tsx:100


WaitForApolloMocks

Ƭ WaitForApolloMocks: (mockIndex?: number) => Promise<void>

Type declaration

▸ (mockIndex?): Promise<void>

Helper method that is returned from render and renderHook. It allows to wait until mocked requests from apolloMocks wrapper are resolved. By default, it will wait for all mocks. Optionally it can receive mockIndex parameter to select the request for which it should wait for

Parameters
NameTypeDescription
mockIndex?numberIndex of the apolloMocks array.
Returns

Promise<void>

Defined in

packages/webapp-libs/webapp-api-client/src/tests/utils/rendering.tsx:51


WrapperProps

Ƭ WrapperProps: Partial<Omit<ApiTestProvidersProps & CoreTestProvidersProps, "apolloMocks">> & { apolloMocks?: ReadonlyArray<MockedResponse> | (mocks: ReadonlyArray<MockedResponse>, storyContext?: StoryContext) => ReadonlyArray<MockedResponse> }

Defined in

packages/webapp-libs/webapp-api-client/src/tests/utils/rendering.tsx:38

Functions

ApiTestProviders

ApiTestProviders(«destructured»): Element

Component that wraps children with Apollo MockerProvider and CommonQuery

Parameters

NameType
«destructured»ApiTestProvidersProps

Returns

Element

Defined in

packages/webapp-libs/webapp-api-client/src/tests/utils/rendering.tsx:30


render

render<Q, Container, BaseElement>(ui, options?): RenderResult<Q, Container, BaseElement> & { waitForApolloMocks: WaitForApolloMocks }

Method that extends render method from @testing-library/react package. It composes a wrapper using ApiTestProviders component and options property that is passed down to parent render method. It also extends returned result with the waitForApolloMocks method.

Type parameters

NameType
Qextends Queries = __module
Containerextends Element | DocumentFragment = HTMLElement
BaseElementextends Element | DocumentFragment = Container

Parameters

NameType
uiReactElement<any, string | JSXElementConstructor<any>>
optionsCustomRenderOptions<Q, Container, BaseElement>

Returns

RenderResult<Q, Container, BaseElement> & { waitForApolloMocks: WaitForApolloMocks }

Defined in

packages/webapp-libs/webapp-api-client/src/tests/utils/rendering.tsx:114


renderHook

renderHook<Result, Props>(hook, options?): Object

Method that extends renderHook method from @testing-library/react package. It composes a wrapper using ApiTestProviders component and options property that is passed down to parent renderHook method. It also extends returned result with the waitForApolloMocks method.

Type parameters

Name
Result
Props

Parameters

NameType
hook(initialProps: Props) => Result
optionsCustomRenderOptions<__module, HTMLElement, HTMLElement>

Returns

Object

NameTypeDescription
rerender(props?: Props) => voidTriggers a re-render. The props will be passed to your renderHook callback.
result{ current: Result }This is a stable reference to the latest value returned by your renderHook callback
result.currentResultThe value returned by your renderHook callback
unmount() => voidUnmounts the test component. This is useful for when you need to test any cleanup your useEffects have.
waitForApolloMocksWaitForApolloMocks-

Defined in

packages/webapp-libs/webapp-api-client/src/tests/utils/rendering.tsx:141