flexpect - v0.21.0
    Preparing search index...
    • Asserts that the target element has sufficient color contrast between its text color and background color, according to the WCAG 2.1 contrast ratio formula.

      The matcher calculates the contrast ratio using the relative luminance of the text color and background color. It fails if the contrast ratio is below the specified minimum, as per WCAG 2.1 guidelines (e.g., 4.5:1 for normal text, 3:1 for large text).

      Parameters

      • element: Locator

        The element as a Locator to check for color contrast.

      • minimumContrastRatio: number

        The minimum acceptable contrast ratio (e.g., 4.5 for AA normal text, 3 for AA large text).

      Returns Promise<MatcherReturnType>

      A Promise that resolves with the matcher result.

      // Assert that a button's text has at least a 4.5:1 contrast ratio with its background
      await expect(buttonLocator).toHaveColorContrast(4.5);