dodil/erp-ui

tests/helpers.tsx

import { render } from "@testing-library/react";
import axe from "axe-core";
import type { ReactElement } from "react";

import { ErpTheme } from "../src/theme";

export function renderInTheme(ui: ReactElement) {
  return render(<ErpTheme>{ui}</ErpTheme>);
}

/** Accessibility violations axe finds (colour contrast needs a real browser and is checked there). */
export async function a11y(container: Element): Promise<string[]> {
  const result = await axe.run(container, { rules: { "color-contrast": { enabled: false } } });
  return result.violations.map((v) => `${v.id}: ${v.help}`);
}