radix.js40 lines · main
| 1 | /** |
| 2 | * Required setup adapted from https://github.com/radix-ui/primitives/issues/856#issuecomment-928704064 |
| 3 | * |
| 4 | * Implements a custom PointerEvent that can then be used to trigger the radix dropdown. |
| 5 | * This is required as JSdom has not implemented the PointerEvent (see https://github.com/testing-library/react-testing-library/issues/838#issuecomment-735259406) |
| 6 | * |
| 7 | * Furthermore, ResizeObserver and DomRect are both not available in JSdom (see https://github.com/radix-ui/primitives/issues/856) |
| 8 | * |
| 9 | * Effects of this setup file: |
| 10 | * - sets PointerEvent to window |
| 11 | * - sets ResizeObserver to window |
| 12 | * - sets DOMRect to window |
| 13 | * |
| 14 | * Needed to interact with dropdown components, with the `clickDropdown` helper. |
| 15 | */ |
| 16 | |
| 17 | class PointerEvent extends Event { |
| 18 | constructor(type, props) { |
| 19 | super(type, props) |
| 20 | if (props.button != null) { |
| 21 | this.button = props.button |
| 22 | } |
| 23 | if (props.ctrlKey != null) { |
| 24 | this.ctrlKey = props.ctrlKey |
| 25 | } |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | window.PointerEvent = PointerEvent |
| 30 | window.HTMLElement.prototype.scrollIntoView = function () {} |
| 31 | |
| 32 | // // https://github.com/radix-ui/primitives/issues/420#issuecomment-771615182 |
| 33 | window.ResizeObserver = class ResizeObserver { |
| 34 | constructor(cb) { |
| 35 | this.cb = cb |
| 36 | } |
| 37 | observe() {} |
| 38 | unobserve() {} |
| 39 | disconnect() {} |
| 40 | } |