Asserts that the element is fully visible within the current viewport, optionally respecting a safety margin from the viewport edges.
┌────────────────────────────────────┐ │ Viewport │ │ │ │ ┌──marginPixel──┐ │ │ │ │ │ │ │ [element] │ ← must be here │ │ │ │ │ │ └───────────────┘ │ └────────────────────────────────────┘ Copy
┌────────────────────────────────────┐ │ Viewport │ │ │ │ ┌──marginPixel──┐ │ │ │ │ │ │ │ [element] │ ← must be here │ │ │ │ │ │ └───────────────┘ │ └────────────────────────────────────┘
The Locator of the element to check.
Optional configuration for margin.
A Promise that resolves with the matcher result.
// Element must be fully in viewport (no margin)await expect(card).toBeWithinViewport(); Copy
// Element must be fully in viewport (no margin)await expect(card).toBeWithinViewport();
// Element must be fully visible with 50px margin from all edgesawait expect(modal).toBeWithinViewport({ marginPixel: 50 }); Copy
// Element must be fully visible with 50px margin from all edgesawait expect(modal).toBeWithinViewport({ marginPixel: 50 });
Asserts that the element is fully visible within the current viewport, optionally respecting a safety margin from the viewport edges.