@testing-library/user-event 12.6.2 → 12.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,6 +7,8 @@ exports.deselectOptions = exports.selectOptions = void 0;
7
7
 
8
8
  var _dom = require("@testing-library/dom");
9
9
 
10
+ var _utils = require("./utils");
11
+
10
12
  var _click = require("./click");
11
13
 
12
14
  var _focus = require("./focus");
@@ -35,7 +37,7 @@ function selectOptionsBase(newValue, select, values, init) {
35
37
  }).filter(option => !option.disabled);
36
38
  if (select.disabled || !selectedOptions.length) return;
37
39
 
38
- if (select instanceof HTMLSelectElement) {
40
+ if ((0, _utils.isInstanceOfElement)(select, 'HTMLSelectElement')) {
39
41
  if (select.multiple) {
40
42
  for (const option of selectedOptions) {
41
43
  // events fired for multiple select are weird. Can't use hover...
package/dist/utils.js CHANGED
@@ -17,10 +17,42 @@ exports.buildTimeValue = buildTimeValue;
17
17
  exports.getValue = getValue;
18
18
  exports.getSelectionRange = getSelectionRange;
19
19
  exports.isContentEditable = isContentEditable;
20
+ exports.isInstanceOfElement = isInstanceOfElement;
20
21
  exports.FOCUSABLE_SELECTOR = void 0;
21
22
 
22
23
  var _dom = require("@testing-library/dom");
23
24
 
25
+ var _helpers = require("@testing-library/dom/dist/helpers");
26
+
27
+ // isInstanceOfElement can be removed once the peerDependency for @testing-library/dom is bumped to a version that includes https://github.com/testing-library/dom-testing-library/pull/885
28
+
29
+ /**
30
+ * Check if an element is of a given type.
31
+ *
32
+ * @param Element The element to test
33
+ * @param string Constructor name. E.g. 'HTMLSelectElement'
34
+ */
35
+ function isInstanceOfElement(element, elementType) {
36
+ try {
37
+ const window = (0, _helpers.getWindowFromNode)(element); // Window usually has the element constructors as properties but is not required to do so per specs
38
+
39
+ if (typeof window[elementType] === 'function') {
40
+ return element instanceof window[elementType];
41
+ }
42
+ } catch (e) {// The document might not be associated with a window
43
+ } // Fall back to the constructor name as workaround for test environments that
44
+ // a) not associate the document with a window
45
+ // b) not provide the constructor as property of window
46
+
47
+
48
+ if (/^HTML(\w+)Element$/.test(element.constructor.name)) {
49
+ return element.constructor.name === elementType;
50
+ } // The user passed some node that is not created in a browser-like environment
51
+
52
+
53
+ throw new Error(`Unable to verify if element is instance of ${elementType}. Please file an issue describing your test environment: https://github.com/testing-library/dom-testing-library/issues/new`);
54
+ }
55
+
24
56
  function isMousePressEvent(event) {
25
57
  return event === 'mousedown' || event === 'mouseup' || event === 'click' || event === 'dblclick';
26
58
  }
@@ -243,7 +275,7 @@ function isFocusable(element) {
243
275
  const CLICKABLE_INPUT_TYPES = ['button', 'color', 'file', 'image', 'reset', 'submit'];
244
276
 
245
277
  function isClickable(element) {
246
- return element.tagName === 'BUTTON' || element instanceof element.ownerDocument.defaultView.HTMLInputElement && CLICKABLE_INPUT_TYPES.includes(element.type);
278
+ return element.tagName === 'BUTTON' || isInstanceOfElement(element, 'HTMLInputElement') && CLICKABLE_INPUT_TYPES.includes(element.type);
247
279
  }
248
280
 
249
281
  function eventWrapper(cb) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testing-library/user-event",
3
- "version": "12.6.2",
3
+ "version": "12.6.3",
4
4
  "description": "Fire events the same way the user does",
5
5
  "main": "dist/index.js",
6
6
  "typings": "typings/index.d.ts",