@testing-library/user-event 14.6.8 → 14.6.10

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.
@@ -49,12 +49,16 @@ function sanitizeValue(element, v) {
49
49
  // Workaround for JSDOM
50
50
  if (isElementType.isElementType(element, 'input', {
51
51
  type: 'number'
52
- }) && String(v) !== '' && !Number.isNaN(Number(v))) {
52
+ }) && String(v) !== '' && !isValidFloatingPointNumber(String(v)) && !Number.isNaN(Number(v))) {
53
53
  // Setting value to "1." results in `null` in JSDOM
54
54
  return String(Number(v));
55
55
  }
56
56
  return String(v);
57
57
  }
58
+ // https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-floating-point-number
59
+ function isValidFloatingPointNumber(v) {
60
+ return /^-?(?:\d+|\d*\.\d+)(?:[eE][-+]?\d+)?$/.test(v);
61
+ }
58
62
  function prepareSelectionInterceptor(element) {
59
63
  prepareInterceptor(element, 'setSelectionRange', function interceptorImpl(start, ...others) {
60
64
  const isUI = UI.isUISelectionStart(start);
@@ -18,7 +18,7 @@ registry.behavior.keypress = (event, target, instance)=>{
18
18
  const submit = form === null || form === void 0 ? void 0 : form.querySelector('input[type="submit"], button:not([type]), button[type="submit"]');
19
19
  if (submit) {
20
20
  return ()=>instance.dispatchUIEvent(submit, 'click');
21
- } else if (form && SubmitSingleInputOnEnter.includes(target.type) && form.querySelectorAll('input').length === 1) {
21
+ } else if (form && SubmitSingleInputOnEnter.includes(target.type) && Array.from(form.querySelectorAll('input')).filter((el)=>BlockImplicitSubmission.includes(el.type)).length === 1) {
22
22
  return ()=>instance.dispatchUIEvent(form, 'submit');
23
23
  } else {
24
24
  return;
@@ -39,6 +39,21 @@ const ClickInputOnEnter = [
39
39
  'reset',
40
40
  'submit'
41
41
  ];
42
+ // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#field-that-blocks-implicit-submission
43
+ const BlockImplicitSubmission = [
44
+ 'date',
45
+ 'datetime-local',
46
+ 'email',
47
+ 'month',
48
+ 'number',
49
+ 'password',
50
+ 'search',
51
+ 'tel',
52
+ 'text',
53
+ 'time',
54
+ 'url',
55
+ 'week'
56
+ ];
42
57
  const SubmitSingleInputOnEnter = [
43
58
  'email',
44
59
  'month',
@@ -47,12 +47,16 @@ function sanitizeValue(element, v) {
47
47
  // Workaround for JSDOM
48
48
  if (isElementType(element, 'input', {
49
49
  type: 'number'
50
- }) && String(v) !== '' && !Number.isNaN(Number(v))) {
50
+ }) && String(v) !== '' && !isValidFloatingPointNumber(String(v)) && !Number.isNaN(Number(v))) {
51
51
  // Setting value to "1." results in `null` in JSDOM
52
52
  return String(Number(v));
53
53
  }
54
54
  return String(v);
55
55
  }
56
+ // https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-floating-point-number
57
+ function isValidFloatingPointNumber(v) {
58
+ return /^-?(?:\d+|\d*\.\d+)(?:[eE][-+]?\d+)?$/.test(v);
59
+ }
56
60
  function prepareSelectionInterceptor(element) {
57
61
  prepareInterceptor(element, 'setSelectionRange', function interceptorImpl(start, ...others) {
58
62
  const isUI = isUISelectionStart(start);
@@ -16,7 +16,7 @@ behavior.keypress = (event, target, instance)=>{
16
16
  const submit = form === null || form === void 0 ? void 0 : form.querySelector('input[type="submit"], button:not([type]), button[type="submit"]');
17
17
  if (submit) {
18
18
  return ()=>instance.dispatchUIEvent(submit, 'click');
19
- } else if (form && SubmitSingleInputOnEnter.includes(target.type) && form.querySelectorAll('input').length === 1) {
19
+ } else if (form && SubmitSingleInputOnEnter.includes(target.type) && Array.from(form.querySelectorAll('input')).filter((el)=>BlockImplicitSubmission.includes(el.type)).length === 1) {
20
20
  return ()=>instance.dispatchUIEvent(form, 'submit');
21
21
  } else {
22
22
  return;
@@ -37,6 +37,21 @@ const ClickInputOnEnter = [
37
37
  'reset',
38
38
  'submit'
39
39
  ];
40
+ // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#field-that-blocks-implicit-submission
41
+ const BlockImplicitSubmission = [
42
+ 'date',
43
+ 'datetime-local',
44
+ 'email',
45
+ 'month',
46
+ 'number',
47
+ 'password',
48
+ 'search',
49
+ 'tel',
50
+ 'text',
51
+ 'time',
52
+ 'url',
53
+ 'week'
54
+ ];
40
55
  const SubmitSingleInputOnEnter = [
41
56
  'email',
42
57
  'month',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testing-library/user-event",
3
- "version": "14.6.8",
3
+ "version": "14.6.10",
4
4
  "description": "Fire events the same way the user does",
5
5
  "keywords": [
6
6
  "react-testing-library",