mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
factor out test helpers (#2093)
This commit is contained in:
parent
4c2d34ffd7
commit
8b9e2a540d
4 changed files with 613 additions and 503 deletions
|
@ -19,14 +19,37 @@ type TestRenderFn = (
|
|||
options?: Omit<RenderOptions, "queries">,
|
||||
) => RenderResult<typeof customQueries>;
|
||||
|
||||
const renderApp: TestRenderFn = (ui, options) =>
|
||||
render(ui, {
|
||||
const renderApp: TestRenderFn = (ui, options) => {
|
||||
const renderResult = render(ui, {
|
||||
queries: customQueries,
|
||||
...options,
|
||||
});
|
||||
|
||||
GlobalTestState.renderResult = renderResult;
|
||||
GlobalTestState.canvas = renderResult.container.querySelector("canvas")!;
|
||||
|
||||
return renderResult;
|
||||
};
|
||||
|
||||
// re-export everything
|
||||
export * from "@testing-library/react";
|
||||
|
||||
// override render method
|
||||
export { renderApp as render };
|
||||
|
||||
/**
|
||||
* For state-sharing across test helpers.
|
||||
* NOTE: there shouldn't be concurrency issues as each test is running in its
|
||||
* own process and thus gets its own instance of this module when running
|
||||
* tests in parallel.
|
||||
*/
|
||||
export class GlobalTestState {
|
||||
/**
|
||||
* automatically updated on each call to render()
|
||||
*/
|
||||
static renderResult: RenderResult<typeof customQueries> = null!;
|
||||
/**
|
||||
* automatically updated on each call to render()
|
||||
*/
|
||||
static canvas: HTMLCanvasElement = null!;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue