flexpect - v0.9.0
    Preparing search index...

    Function toHaveAspectRatio

    • 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
      • ratio: number

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

      • options: ToHaveAspectRatioOptions = {}

        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, {
      tolerancePercent: 3,
      });