Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | 38x 38x 59x 59x 59x 59x 30x 30x 30x 30x 38x 38x 6x 6x 1x 1x 1x 2x 2x | import { fireEvent, screen } from "@testing-library/react";
import mediaQuery from "css-mediaquery";
export function addDefaultUser(userId?: number) {
window.localStorage.setItem("auth.authenticated", JSON.stringify(true));
window.localStorage.setItem("auth.jailed", JSON.stringify(false));
window.localStorage.setItem(
"auth.userId",
JSON.stringify(userId ?? defaultUser.userId),
);
}
export async function assertErrorAlert(message: string) {
const errorAlert = await screen.findByRole("alert");
expect(errorAlert).toBeVisible();
expect(errorAlert).toHaveTextContent(message);
}
export function mockConsoleError() {
jest.spyOn(console, "error").mockReturnValue(undefined);
}
export function wait(milliSeconds: number) {
return new Promise<void>((resolve) => setTimeout(resolve, milliSeconds));
}
//eslint-disable-next-line
export type MockedService<T extends (...args: any) => any> = jest.Mock<
ReturnType<T>,
Parameters<T>
>;
export function keyPress(
element: Window | Document | Node | Element,
keyEvent: { code: string; key: string },
) {
fireEvent.keyDown(element, keyEvent);
fireEvent.keyUp(element, keyEvent);
}
export function createMatchMedia(width: number) {
return (query: string) => ({
matches: mediaQuery.match(query, { width }),
media: "screen",
addListener: jest.fn(),
removeListener: jest.fn(),
onchange: jest.fn(),
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(),
});
}
|