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
Name | Type |
---|---|
Q | extends Queries = typeof queries |
Container | extends Element | DocumentFragment = HTMLElement |
BaseElement | extends 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
Name | Type | Description |
---|---|---|
mockIndex? | number | Index 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
Name | Type |
---|---|
«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
Name | Type |
---|---|
Q | extends Queries = __module |
Container | extends Element | DocumentFragment = HTMLElement |
BaseElement | extends Element | DocumentFragment = Container |
Parameters
Name | Type |
---|---|
ui | ReactElement <any , string | JSXElementConstructor <any >> |
options | CustomRenderOptions <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
Name | Type |
---|---|
hook | (initialProps : Props ) => Result |
options | CustomRenderOptions <__module , HTMLElement , HTMLElement > |
Returns
Object
Name | Type | Description |
---|---|---|
rerender | (props? : Props ) => void | Triggers 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.current | Result | The value returned by your renderHook callback |
unmount | () => void | Unmounts the test component. This is useful for when you need to test any cleanup your useEffects have. |
waitForApolloMocks | WaitForApolloMocks | - |
Defined in
packages/webapp-libs/webapp-api-client/src/tests/utils/rendering.tsx:141