flexpect - v0.21.0
    Preparing search index...
    • Asserts that the target element has the specified aspect ratio (width divided by height), within an optional tolerance percentage.

      This assertion calculates the aspect ratio of the element by dividing its width by its height, then compares it to the expected ratio. If the actual ratio falls outside the allowed tolerance, a detailed message is returned to help diagnose the discrepancy.

      The aspect ratio is defined as:

      aspectRatio = width / height
      

      Parameters

      • element: Locator

        The element as a Locator to check for aspect ratio.

      • expectedRatio: number

        The expected aspect ratio (width / height) to check against.

      • options: Tolerance = {}

        Optional comparison options.

      Returns Promise<MatcherReturnType>

      A Promise that resolves with the matcher result.

      // Checks that the element has an aspect ratio of 16:9 exactly (no tolerance)
      await expect(elementLocator).toHaveAspectRatio(16 / 9);
      // Checks that the element has an aspect ratio close to 4:3 within 3% tolerance
      await expect(elementLocator).toHaveAspectRatio(4 / 3, {
      tolerance: 3,
      toleranceUnit: ToleranceUnit.Percent
      });