flexpect - v0.21.0
    Preparing search index...
    • Asserts that the spacing between two elements matches the expected value along the specified axis.

      The spacing is calculated as the gap between the edges of the two elements:

      • Horizontal: distance between the right edge of the left element and the left edge of the right element.
      • Vertical: distance between the bottom edge of the top element and the top edge of the bottom element.

      Elements are automatically ordered by position (left → right or top → bottom), regardless of parameter order.

      • Horizontal spacing (axis = SpacingAxis.Horizontal):
      ┌───────────┐                ┌───────────┐
      │ Element A │◄── 16px gap ──►│ Element B │
      └───────────┘                └───────────┘
      
      • Vertical spacing (axis = SpacingAxis.Vertical):
      ┌───────────────┐
      │   Element A   │
      └───────────────┘
              ▲
              │ 16px gap
              ▼
      ┌───────────────┐
      │   Element B   │
      └───────────────┘
      
      • No spacing (elements touching):
      ┌───────────┐┌───────────┐
      │ Element A ││ Element B │
      └───────────┘└───────────┘
                   ◄─ 0px gap ─►
      
      • Overlapping elements (negative spacing):
      ┌───────────┼───────────┐
      │ Element A │ Element B │
      └───────────┼───────────┘
                  │
              ◄─overlap─►
      

      Parameters

      • element: Locator

        The first element as a Locator.

      • reference: Locator

        The reference element as a Locator relative to which spacing is measured.

      • expectedSpacing: number

        Expected gap between the two elements, in pixels (≥ 0).

      • axis: SpacingAxis

        The axis along which to measure spacing.

      • options: Tolerance = {}

        Optional spacing options.

      Returns Promise<MatcherReturnType>

      A Promise that resolves with the matcher result.

      // Horizontal spacing: exactly 16px
      await expect(button1).toHaveSpacingBetween(button2, 16, SpacingAxis.Horizontal);
      // Vertical spacing: 24px ± 5%
      await expect(header).toHaveSpacingBetween(content, 24, SpacingAxis.Vertical, {
      tolerance: 5,
      toleranceUnit: ToleranceUnit.Percent
      });