flexpect - v0.9.0
    Preparing search index...

    Function toBeAlignedWith

    • Asserts that the target element is aligned with the specified container element based on the provided axis and alignment mode, considering an optional tolerance percentage.

      This assertion compares the position of the element relative to the container along the given axis (horizontal or vertical) and verifies if it matches the expected alignment mode (start, center, or end).

      If the alignment falls outside the allowed tolerance, a detailed message is returned to help diagnose the misalignment.

      • Horizontal axis (axis = 'horizontal'):

        • Start (mode = start'):
          |[element]------------------|
          |                           |
          |                           |
          
        • Center (mode = 'center'):
          |---------[element]---------|
          |                           |
          |                           |
          
        • End (mode = 'end'):
          |------------------[element]|
          |                           |
          |                           |
          
      • Vertical axis (axis = 'vertical'):

        • Start (mode = 'start'):
          |[element]                  |
          |                           |
          |                           |
          
        • Center (mode = 'center'):
          |                           |
          |         [element]         |
          |                           |
          
        • End (mode = 'end'):
          |                           |
          |                           |
          |                  [element]|
          

      Parameters

      • element: Locator
      • container: Locator

        The container element as a Locator relative to which alignment is checked.

      • axis: Axis

        The axis along which to check alignment (horizontal or vertical).

      • mode: Alignment

        The alignment mode to check (start, center, or end).

      • options: ToBeAlignedWithOptions = {}

        Optional alignment options.

      Returns Promise<MatcherReturnType>

      A Promise that resolves with the matcher result.

      // Checks that the button is horizontally centered with its parent within 2% tolerance
      await expect(buttonLocator).toBeAlignedWith(parentLocator, Axis.Horizontal, Alignment.Center, {
      tolerancePercent: 2,
      });
      // Checks that the button is aligned to the start vertically with no tolerance
      await expect(buttonLocator).toBeAlignedWith(parentLocator, Axis.Vertical, Alignment.Start);