import { axeRuntimeExceptionMsgPrefix } from '@sa11y/common' ; /**
 * Cartesian product of arrays
 * Ref: https://eddmann.com/posts/cartesian-product-in-javascript/
 */ export function cartesianProduct ( ... sets ) { const flatten = ( arr ) : Array < any > => [ ] . concat ( [ ] , ... arr ) ; return sets . reduce ( ( acc , set ) => flatten ( acc . map ( ( x ) => set . map ( ( y ) => [ ... x , y ] ) ) ) , [ [ ] ] ) ; } /**
 * Common Jest setup that sets up JSDOM as required for the tests
 */ export function beforeEachSetup ( ) { document . documentElement . lang = 'en' ; document . body . innerHTML = '' ; } /**
 * Check if given error is an a11y error and not an axe runtime exception.
 * Make sure to use `expect.assertions(..)` before calling this method esp in the `catch`
 * block to make sure the test is not passing without running into the `catch` block.
 */ export function checkA11yError ( e ) { expect ( e ) . toBeTruthy ( ) ; expect ( e . message ) . not . toContain ( axeRuntimeExceptionMsgPrefix ) ; expect ( e . message ) . toMatchSnapshot ( ) ; } /**
 * Check error thrown by calling given function.
 * Preferable to using `checkA11yError` with `expect.assertions(..)` due to
 * https://github.com/jest-community/eslint-plugin-jest/blob/main/docs/rules/no-conditional-expect.md
 */ export async function checkA11yErrorFunc ( errorThrower , expectRuntimeError = false , expectNoError = false ) { expect . hasAssertions ( ) ; let err = new Error ( ) ; try { await errorThrower ( ) ; } catch ( e ) { err = e as Error ; } finally { if ( expectNoError ) { expect ( err . message ) . toHaveLength ( 0 ) ; } else if ( expectRuntimeError ) { expect ( err . message ) . toContain ( axeRuntimeExceptionMsgPrefix ) ; } else { checkA11yError ( err ) ; } } }