shlink-web-client/test/__helpers__/setUpTest.ts

21 lines
694 B
TypeScript
Raw Normal View History

import { render } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
2023-02-18 13:11:01 +03:00
import type { ReactElement } from 'react';
export const setUpCanvas = (element: ReactElement) => {
const result = render(element);
const { container } = result;
2023-05-27 13:45:06 +03:00
const getEvents = () => {
const context = container.querySelector('canvas')?.getContext('2d');
// @ts-expect-error __getEvents is set by vitest-canvas-mock
return context?.__getEvents(); // eslint-disable-line no-underscore-dangle
};
return { ...result, events: getEvents(), getEvents };
};
export const renderWithEvents = (element: ReactElement) => ({
user: userEvent.setup(),
...render(element),
});