2020-03-07 10:20:38 -05:00
|
|
|
import "pepjs";
|
|
|
|
|
2020-02-12 02:19:43 +04:00
|
|
|
import {
|
|
|
|
render,
|
|
|
|
queries,
|
|
|
|
RenderResult,
|
|
|
|
RenderOptions,
|
|
|
|
} from "@testing-library/react";
|
|
|
|
|
|
|
|
import * as toolQueries from "./queries/toolQueries";
|
|
|
|
|
|
|
|
const customQueries = {
|
|
|
|
...queries,
|
|
|
|
...toolQueries,
|
|
|
|
};
|
|
|
|
|
|
|
|
type TestRenderFn = (
|
|
|
|
ui: React.ReactElement,
|
|
|
|
options?: Omit<RenderOptions, "queries">,
|
|
|
|
) => RenderResult<typeof customQueries>;
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
const renderApp: TestRenderFn = (ui, options) => {
|
|
|
|
const renderResult = render(ui, {
|
2020-02-12 02:19:43 +04:00
|
|
|
queries: customQueries,
|
|
|
|
...options,
|
|
|
|
});
|
|
|
|
|
2020-08-28 10:15:29 +02:00
|
|
|
GlobalTestState.renderResult = renderResult;
|
|
|
|
GlobalTestState.canvas = renderResult.container.querySelector("canvas")!;
|
|
|
|
|
|
|
|
return renderResult;
|
|
|
|
};
|
|
|
|
|
2020-02-12 02:19:43 +04:00
|
|
|
// re-export everything
|
|
|
|
export * from "@testing-library/react";
|
|
|
|
|
|
|
|
// override render method
|
|
|
|
export { renderApp as render };
|
2020-08-28 10:15:29 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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!;
|
|
|
|
}
|