Skip to content

Commit

Permalink
test(@react-aria/overlays): add two test case for close on scroll
Browse files Browse the repository at this point in the history
related to #2340.

The first test case is related to the regression mentioned here: #2341 (comment)

The second test case captures the fix for the cypress issue.
  • Loading branch information
alirezamirian committed Sep 27, 2021
1 parent a7abbdb commit c5f5266
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/@react-aria/overlays/test/useOverlayPosition.test.js
Expand Up @@ -163,6 +163,25 @@ describe('useOverlayPosition', function () {
fireEvent.scroll(document.body);
expect(onClose).toHaveBeenCalledTimes(1);
});

it('should close the overlay when the document scrolls', function () {
let onClose = jest.fn();
render(<Example isOpen onClose={onClose} />);

fireEvent.scroll(document);
expect(onClose).toHaveBeenCalledTimes(1);
});

it('should not throw or close when target is window in a scroll event', function () {
// Cypress triggers an artificial scroll event in `screenshot` command:
// https://github.com/cypress-io/cypress/blob/develop/packages/driver/src/cy/commands/screenshot.ts#L106
// More info: https://github.com/adobe/react-spectrum/issues/2340
let onClose = jest.fn();
render(<Example isOpen onClose={onClose} />);

fireEvent.scroll(window);
expect(onClose).toHaveBeenCalledTimes(0);
});
});

describe('useOverlayPosition with positioned container', () => {
Expand Down

0 comments on commit c5f5266

Please sign in to comment.