@enact/core 4.5.2 → 4.6.1

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.
Files changed (61) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dispatcher/dispatcher.js +15 -27
  3. package/dispatcher/listeners.js +0 -8
  4. package/dispatcher/tests/dispatcher-specs.js +0 -3
  5. package/handle/handle.js +40 -98
  6. package/handle/tests/handle-specs.js +21 -42
  7. package/hoc/hoc.js +2 -13
  8. package/hoc/tests/hoc-specs.js +0 -23
  9. package/internal/ApiDecorator/ApiDecorator.js +4 -34
  10. package/internal/ApiDecorator/tests/ApiDecorator-specs.js +69 -40
  11. package/internal/Registry/Registry.js +0 -7
  12. package/internal/Registry/tests/Registry-specs.js +26 -78
  13. package/internal/deprecate/deprecate.js +9 -22
  14. package/internal/deprecate/tests/deprecate-specs.js +38 -0
  15. package/internal/prop-types/prop-types.js +3 -20
  16. package/internal/prop-types/tests/prop-types-specs.js +265 -0
  17. package/keymap/index.js +2 -3
  18. package/keymap/keymap.js +10 -18
  19. package/keymap/tests/keymap-specs.js +0 -3
  20. package/kind/computed.js +2 -9
  21. package/kind/kind.js +14 -53
  22. package/kind/styles.js +6 -19
  23. package/kind/tests/computed-specs.js +4 -6
  24. package/kind/tests/kind-specs.js +9 -44
  25. package/kind/tests/styles-specs.js +12 -7
  26. package/kind/util.js +0 -2
  27. package/package.json +8 -2
  28. package/platform/platform.js +51 -57
  29. package/platform/tests/platform-specs.js +31 -3
  30. package/snapshot/snapshot.js +4 -9
  31. package/snapshot/tests/snapshot-specs.js +56 -0
  32. package/useChainRefs/tests/useChainRefs-specs.js +0 -14
  33. package/useChainRefs/useChainRefs.js +3 -11
  34. package/useClass/tests/useClass-specs.js +6 -21
  35. package/useClass/useClass.js +0 -8
  36. package/useHandlers/Handlers.js +0 -11
  37. package/useHandlers/tests/useHandlers-specs.js +11 -23
  38. package/useHandlers/useHandlers.js +0 -5
  39. package/usePublicClassNames/tests/usePublicClassNames-specs.js +21 -28
  40. package/usePublicClassNames/usePublicClassNames.js +4 -10
  41. package/util/Job.js +1 -43
  42. package/util/tests/Job-specs.js +48 -14
  43. package/util/tests/util-specs.js +125 -10
  44. package/util/util.js +15 -54
  45. package/dispatcher/dispatcher.d.ts +0 -21
  46. package/handle/handle.d.ts +0 -618
  47. package/hoc/hoc.d.ts +0 -44
  48. package/index.d.ts +0 -0
  49. package/internal/ApiDecorator/ApiDecorator.d.ts +0 -0
  50. package/internal/Registry/Registry.d.ts +0 -0
  51. package/internal/deprecate/deprecate.d.ts +0 -0
  52. package/internal/prop-types/prop-types.d.ts +0 -0
  53. package/keymap/index.d.ts +0 -37
  54. package/kind/kind.d.ts +0 -90
  55. package/platform/platform.d.ts +0 -45
  56. package/snapshot/snapshot.d.ts +0 -32
  57. package/useChainRefs/useChainRefs.d.ts +0 -0
  58. package/useClass/useClass.d.ts +0 -0
  59. package/useHandlers/useHandlers.d.ts +0 -0
  60. package/usePublicClassNames/usePublicClassNames.d.ts +0 -0
  61. package/util/util.d.ts +0 -162
@@ -4,34 +4,25 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = exports.Handlers = void 0;
7
-
8
7
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
9
-
10
8
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
11
-
12
9
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
13
-
14
10
  var Handlers = /*#__PURE__*/function () {
15
11
  function Handlers(_handlers) {
16
12
  var _this = this;
17
-
18
13
  _classCallCheck(this, Handlers);
19
-
20
14
  this.props = {};
21
15
  this.context = {};
22
16
  this._handlers = {};
23
-
24
17
  if (_handlers) {
25
18
  Object.keys(_handlers).forEach(function (fn) {
26
19
  _this._handlers[fn] = function (ev) {
27
20
  return _handlers[fn](ev, _this.props, _this.context);
28
21
  };
29
-
30
22
  _this._handlers[fn].displayName = fn;
31
23
  });
32
24
  }
33
25
  }
34
-
35
26
  _createClass(Handlers, [{
36
27
  key: "handlers",
37
28
  get: function get() {
@@ -46,10 +37,8 @@ var Handlers = /*#__PURE__*/function () {
46
37
  this.context = context;
47
38
  }
48
39
  }]);
49
-
50
40
  return Handlers;
51
41
  }();
52
-
53
42
  exports.Handlers = Handlers;
54
43
  var _default = Handlers;
55
44
  exports["default"] = _default;
@@ -1,27 +1,18 @@
1
1
  "use strict";
2
2
 
3
3
  require("@testing-library/jest-dom");
4
-
5
4
  var _react = require("@testing-library/react");
6
-
7
5
  var _useHandlers = _interopRequireDefault(require("../useHandlers"));
8
-
9
6
  var _jsxRuntime = require("react/jsx-runtime");
10
-
11
7
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
12
-
13
8
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
14
-
15
9
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
16
-
17
10
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
18
-
19
11
  describe('useHandlers', function () {
20
12
  var data = {};
21
13
  var context = {
22
14
  value: 1
23
15
  };
24
-
25
16
  function Component(props) {
26
17
  var handlers = (0, _useHandlers["default"])({
27
18
  testEvent: function testEvent(ev, p, c) {
@@ -34,9 +25,9 @@ describe('useHandlers', function () {
34
25
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread(_objectSpread({}, props), {}, {
35
26
  "data-testid": "divComponent"
36
27
  }));
37
- } // Sanity test for Component moreso than useHandlers test
38
-
28
+ }
39
29
 
30
+ // Sanity test for Component moreso than useHandlers test
40
31
  test('should include handlers in props', function () {
41
32
  (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {}));
42
33
  var actual = data.handlers.testEvent;
@@ -44,8 +35,7 @@ describe('useHandlers', function () {
44
35
  });
45
36
  test('should have the same reference across renders', function () {
46
37
  var _render = (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {})),
47
- rerender = _render.rerender;
48
-
38
+ rerender = _render.rerender;
49
39
  var expected = data.handlers.testEvent;
50
40
  rerender( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {}));
51
41
  var actual = data.handlers.testEvent;
@@ -53,10 +43,8 @@ describe('useHandlers', function () {
53
43
  });
54
44
  test('should receive the event', function () {
55
45
  var spy = jest.fn();
56
-
57
46
  var _render2 = (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {})),
58
- rerender = _render2.rerender;
59
-
47
+ rerender = _render2.rerender;
60
48
  rerender( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
61
49
  children: 'updated'
62
50
  }));
@@ -65,10 +53,8 @@ describe('useHandlers', function () {
65
53
  });
66
54
  test('should reflect the latest props', function () {
67
55
  var spy = jest.fn();
68
-
69
56
  var _render3 = (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {})),
70
- rerender = _render3.rerender;
71
-
57
+ rerender = _render3.rerender;
72
58
  rerender( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
73
59
  children: 'updated'
74
60
  }));
@@ -82,9 +68,10 @@ describe('useHandlers', function () {
82
68
  test('should support component-driven context', function () {
83
69
  var spy = jest.fn();
84
70
  (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {}));
85
- data.handlers.testEvent(spy); // defined a "global" context to ease testability but this isn't representative of the
86
- // expected use case of this feature.
71
+ data.handlers.testEvent(spy);
87
72
 
73
+ // defined a "global" context to ease testability but this isn't representative of the
74
+ // expected use case of this feature.
88
75
  var expected = context;
89
76
  var actual = spy.mock.calls[0][1];
90
77
  expect(actual).toMatchObject(expected);
@@ -94,9 +81,10 @@ describe('useHandlers', function () {
94
81
  return 'ok';
95
82
  });
96
83
  (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {}));
97
- var returnValue = data.handlers.testEvent(spy); // defined a "global" context to ease testability but this isn't representative of the
98
- // expected use case of this feature.
84
+ var returnValue = data.handlers.testEvent(spy);
99
85
 
86
+ // defined a "global" context to ease testability but this isn't representative of the
87
+ // expected use case of this feature.
100
88
  var expected = 'ok';
101
89
  expect(returnValue).toBe(expected);
102
90
  });
@@ -5,13 +5,9 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports["default"] = void 0;
7
7
  exports.useHandlers = useHandlers;
8
-
9
8
  var _useClass = _interopRequireDefault(require("../useClass"));
10
-
11
9
  var _Handlers = _interopRequireDefault(require("./Handlers"));
12
-
13
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
14
-
15
11
  /**
16
12
  * Creates a map of event handlers with consistent references across renders.
17
13
  *
@@ -31,6 +27,5 @@ function useHandlers(handlers, props, context) {
31
27
  h.setContext(props, context);
32
28
  return h.handlers;
33
29
  }
34
-
35
30
  var _default = useHandlers;
36
31
  exports["default"] = _default;
@@ -1,11 +1,8 @@
1
1
  "use strict";
2
2
 
3
3
  var _react = require("@testing-library/react");
4
-
5
4
  var _usePublicClassNames = _interopRequireDefault(require("../usePublicClassNames"));
6
-
7
5
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
8
-
9
6
  describe('usePublicClassNames', function () {
10
7
  var componentCss = {
11
8
  test: 'test-class',
@@ -22,28 +19,25 @@ describe('usePublicClassNames', function () {
22
19
  var testComponentCss = {
23
20
  test: 'test-class'
24
21
  };
25
-
26
22
  var _renderHook = (0, _react.renderHook)(function () {
27
- return (0, _usePublicClassNames["default"])({
28
- componentCss: testComponentCss,
29
- customCss: null,
30
- publicClassNames: true
31
- });
32
- }),
33
- result = _renderHook.result;
34
-
23
+ return (0, _usePublicClassNames["default"])({
24
+ componentCss: testComponentCss,
25
+ customCss: null,
26
+ publicClassNames: true
27
+ });
28
+ }),
29
+ result = _renderHook.result;
35
30
  expect(result.current).toEqual(testComponentCss);
36
31
  });
37
32
  test('should return a merged css has all keys from `componentCss` and merged values when `publicClassNames` is true', function () {
38
33
  var _renderHook2 = (0, _react.renderHook)(function () {
39
- return (0, _usePublicClassNames["default"])({
40
- componentCss: componentCss,
41
- customCss: customCss,
42
- publicClassNames: true
43
- });
44
- }),
45
- result = _renderHook2.result;
46
-
34
+ return (0, _usePublicClassNames["default"])({
35
+ componentCss: componentCss,
36
+ customCss: customCss,
37
+ publicClassNames: true
38
+ });
39
+ }),
40
+ result = _renderHook2.result;
47
41
  var expected = {
48
42
  test: 'test-class test-class-custom',
49
43
  a: 'a-class a-class-custom',
@@ -55,14 +49,13 @@ describe('usePublicClassNames', function () {
55
49
  });
56
50
  test('should return a merged css has the keys from `publicClassNames` array and merged values when `publicClassNames` is an array of strings', function () {
57
51
  var _renderHook3 = (0, _react.renderHook)(function () {
58
- return (0, _usePublicClassNames["default"])({
59
- componentCss: componentCss,
60
- customCss: customCss,
61
- publicClassNames: ['a', 'b']
62
- });
63
- }),
64
- result = _renderHook3.result;
65
-
52
+ return (0, _usePublicClassNames["default"])({
53
+ componentCss: componentCss,
54
+ customCss: customCss,
55
+ publicClassNames: ['a', 'b']
56
+ });
57
+ }),
58
+ result = _renderHook3.result;
66
59
  var expected = {
67
60
  a: 'a-class a-class-custom',
68
61
  b: 'b-class b-class-custom'
@@ -5,9 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports["default"] = void 0;
7
7
  exports.usePublicClassNames = usePublicClassNames;
8
-
9
8
  var _util = require("../util");
10
-
11
9
  /**
12
10
  * A hook for supporting `publicClassNames` to functional components.
13
11
  * It returns merged CSS of given two CSS objects according to `publicClassNames` option.
@@ -23,28 +21,24 @@ var _util = require("../util");
23
21
  */
24
22
  function usePublicClassNames(_ref) {
25
23
  var componentCss = _ref.componentCss,
26
- customCss = _ref.customCss,
27
- publicClassNames = _ref.publicClassNames;
24
+ customCss = _ref.customCss,
25
+ publicClassNames = _ref.publicClassNames;
28
26
  var allowedClassNames = publicClassNames;
29
27
  var mergedCss = componentCss;
30
-
31
28
  if (!componentCss || !customCss) {
32
29
  return mergedCss;
33
30
  }
34
-
35
31
  if (allowedClassNames === true) {
36
32
  allowedClassNames = Object.keys(componentCss);
37
33
  } else if (typeof allowedClassNames === 'string') {
38
34
  allowedClassNames = allowedClassNames.split(/\s+/);
39
- } // if the config includes a css map, merge them together now
40
-
35
+ }
41
36
 
37
+ // if the config includes a css map, merge them together now
42
38
  if (allowedClassNames) {
43
39
  mergedCss = (0, _util.mergeClassNameMaps)(componentCss, customCss, allowedClassNames);
44
40
  }
45
-
46
41
  return mergedCss;
47
42
  }
48
-
49
43
  var _default = usePublicClassNames;
50
44
  exports["default"] = _default;
package/util/Job.js CHANGED
@@ -4,17 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = exports.Job = void 0;
7
-
8
7
  var _invariant = _interopRequireDefault(require("invariant"));
9
-
10
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
11
-
12
9
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
13
-
14
10
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
15
-
16
11
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
17
-
18
12
  /**
19
13
  * Provides a convenient way to manage timed execution of functions.
20
14
  *
@@ -32,35 +26,27 @@ var Job = /*#__PURE__*/function () {
32
26
  */
33
27
  function Job(fn, _timeout) {
34
28
  var _this = this;
35
-
36
29
  _classCallCheck(this, Job);
37
-
38
30
  this.id = null;
39
31
  this.fn = null;
40
32
  this.timeout = null;
41
33
  this.type = null;
42
-
43
34
  this.start = function () {
44
35
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
45
36
  args[_key] = arguments[_key];
46
37
  }
47
-
48
38
  _this.startAfter.apply(_this, [_this.timeout].concat(args));
49
39
  };
50
-
51
40
  this.startAfter = function (timeout) {
52
41
  for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
53
42
  args[_key2 - 1] = arguments[_key2];
54
43
  }
55
-
56
44
  _this.stop();
57
-
58
45
  _this.type = 'timeout';
59
46
  _this.id = setTimeout(function () {
60
47
  return _this.run(args);
61
48
  }, timeout);
62
49
  };
63
-
64
50
  this.stop = function () {
65
51
  if (_this.id) {
66
52
  if (_this.type === 'idle') {
@@ -70,49 +56,37 @@ var Job = /*#__PURE__*/function () {
70
56
  } else if (_this.type === 'timeout') {
71
57
  clearTimeout(_this.id);
72
58
  }
73
-
74
59
  _this.id = _this.type = null;
75
60
  }
76
61
  };
77
-
78
62
  this.throttle = function () {
79
63
  for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
80
64
  args[_key3] = arguments[_key3];
81
65
  }
82
-
83
66
  _this.throttleUntil.apply(_this, [_this.timeout].concat(args));
84
67
  };
85
-
86
68
  this.throttleUntil = function (timeout) {
87
69
  if (!_this.id) {
88
70
  _this.type = 'timeout';
89
-
90
71
  for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
91
72
  args[_key4 - 1] = arguments[_key4];
92
73
  }
93
-
94
74
  _this.run(args);
95
-
96
75
  _this.id = setTimeout(_this.stop, timeout);
97
76
  }
98
77
  };
99
-
100
78
  this.idle = function () {
101
79
  for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
102
80
  args[_key5] = arguments[_key5];
103
81
  }
104
-
105
82
  _this.idleUntil.apply(_this, [null].concat(args));
106
83
  };
107
-
108
84
  this.idleUntil = function (timeout) {
109
85
  for (var _len6 = arguments.length, args = new Array(_len6 > 1 ? _len6 - 1 : 0), _key6 = 1; _key6 < _len6; _key6++) {
110
86
  args[_key6 - 1] = arguments[_key6];
111
87
  }
112
-
113
88
  if (typeof window !== 'undefined' && window.requestIdleCallback) {
114
89
  _this.stop();
115
-
116
90
  _this.type = 'idle';
117
91
  _this.id = window.requestIdleCallback(function () {
118
92
  return _this.run(args);
@@ -124,49 +98,38 @@ var Job = /*#__PURE__*/function () {
124
98
  _this.startAfter.apply(_this, [timeout].concat(args));
125
99
  }
126
100
  };
127
-
128
101
  this.startRaf = function () {
129
102
  for (var _len7 = arguments.length, args = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
130
103
  args[_key7] = arguments[_key7];
131
104
  }
132
-
133
105
  _this.startRafAfter.apply(_this, [_this.timeout].concat(args));
134
106
  };
135
-
136
107
  this.startRafAfter = function (timeout) {
137
108
  for (var _len8 = arguments.length, args = new Array(_len8 > 1 ? _len8 - 1 : 0), _key8 = 1; _key8 < _len8; _key8++) {
138
109
  args[_key8 - 1] = arguments[_key8];
139
110
  }
140
-
141
111
  _this.type = 'raf';
142
-
143
112
  if (typeof window !== 'undefined') {
144
113
  var time = null;
145
-
146
114
  var callback = function callback(timestamp) {
147
115
  if (time === null) {
148
116
  time = timestamp;
149
117
  }
150
-
151
118
  if (timeout && timestamp - time < timeout) {
152
119
  _this.id = window.requestAnimationFrame(callback);
153
120
  } else {
154
121
  time = null;
155
-
156
122
  _this.run(args);
157
-
158
123
  window.cancelAnimationFrame(_this.id);
159
124
  _this.id = null;
160
125
  }
161
126
  };
162
-
163
127
  _this.id = window.requestAnimationFrame(callback);
164
128
  } else {
165
129
  // If requestAnimationFrame is not supported just run the function immediately
166
130
  _this.run(args);
167
131
  }
168
132
  };
169
-
170
133
  this.promise = function (promise) {
171
134
  !(promise && typeof promise.then === 'function') ? process.env.NODE_ENV !== "production" ? (0, _invariant["default"])(false, 'promise expects a thenable') : (0, _invariant["default"])(false) : void 0;
172
135
  _this.type = 'promise';
@@ -174,22 +137,20 @@ var Job = /*#__PURE__*/function () {
174
137
  return promise.then(function (result) {
175
138
  if (_this.id === promise) {
176
139
  _this.stop();
177
-
178
140
  return _this.run([result]);
179
141
  }
180
142
  });
181
143
  };
182
-
183
144
  this.fn = fn;
184
145
  this.timeout = _timeout;
185
146
  }
186
-
187
147
  _createClass(Job, [{
188
148
  key: "run",
189
149
  value: function run(args) {
190
150
  // don't want to inadvertently apply Job's context on `fn`
191
151
  return this.fn.apply(null, args);
192
152
  }
153
+
193
154
  /**
194
155
  * Starts the job.
195
156
  *
@@ -200,12 +161,9 @@ var Job = /*#__PURE__*/function () {
200
161
  * @memberof core/util.Job.prototype
201
162
  * @public
202
163
  */
203
-
204
164
  }]);
205
-
206
165
  return Job;
207
166
  }();
208
-
209
167
  exports.Job = Job;
210
168
  var _default = Job;
211
169
  exports["default"] = _default;
@@ -1,11 +1,8 @@
1
1
  "use strict";
2
2
 
3
3
  var _react = require("@testing-library/react");
4
-
5
4
  var _Job = _interopRequireDefault(require("../Job"));
6
-
7
5
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
8
-
9
6
  describe('Job', function () {
10
7
  beforeEach(function () {
11
8
  jest.useFakeTimers();
@@ -21,7 +18,6 @@ describe('Job', function () {
21
18
  });
22
19
  test('should pass args to fn', function (done) {
23
20
  var value = 'argument';
24
-
25
21
  var fn = function fn(arg) {
26
22
  if (arg === value) {
27
23
  done();
@@ -29,7 +25,6 @@ describe('Job', function () {
29
25
  done(new Error('fn did not receive argument'));
30
26
  }
31
27
  };
32
-
33
28
  var j = new _Job["default"](fn, 10);
34
29
  j.start(value);
35
30
  jest.runAllTimers();
@@ -49,6 +44,19 @@ describe('Job', function () {
49
44
  });
50
45
  if (!ran) done();
51
46
  });
47
+ test('should stop requestAnimationFrame job', function (done) {
48
+ var ran = false;
49
+ var j = new _Job["default"](function () {
50
+ ran = true;
51
+ done(new Error('job wasn\'t stopped'));
52
+ }, 10);
53
+ j.startRaf();
54
+ j.stop();
55
+ (0, _react.act)(function () {
56
+ return jest.advanceTimersByTime(30);
57
+ });
58
+ if (!ran) done();
59
+ });
52
60
  });
53
61
  describe('#throttle', function () {
54
62
  test('should throttle job', function (done) {
@@ -72,7 +80,6 @@ describe('Job', function () {
72
80
  (0, _react.act)(function () {
73
81
  return jest.advanceTimersByTime(5);
74
82
  });
75
-
76
83
  if (number === 2) {
77
84
  done();
78
85
  } else {
@@ -81,7 +88,6 @@ describe('Job', function () {
81
88
  });
82
89
  test('should pass args to fn', function (done) {
83
90
  var value = 'argument';
84
-
85
91
  var fn = function fn(arg) {
86
92
  if (arg === value) {
87
93
  done();
@@ -89,7 +95,6 @@ describe('Job', function () {
89
95
  done(new Error('fn did not receive argument'));
90
96
  }
91
97
  };
92
-
93
98
  var j = new _Job["default"](fn, 10);
94
99
  j.throttle(value);
95
100
  });
@@ -102,7 +107,6 @@ describe('Job', function () {
102
107
  window.requestIdleCallback = windowRequest || function (fn) {
103
108
  return setTimeout(fn, 0);
104
109
  };
105
-
106
110
  window.cancelIdleCallback = windowCancel || function (id) {
107
111
  clearTimeout(id);
108
112
  };
@@ -118,7 +122,6 @@ describe('Job', function () {
118
122
  });
119
123
  test('should pass args to fn', function (done) {
120
124
  var value = 'argument';
121
-
122
125
  var fn = function fn(arg) {
123
126
  if (arg === value) {
124
127
  done();
@@ -126,7 +129,6 @@ describe('Job', function () {
126
129
  done(new Error('fn did not receive argument'));
127
130
  }
128
131
  };
129
-
130
132
  var j = new _Job["default"](fn, 10);
131
133
  j.idle(value);
132
134
  jest.runAllTimers();
@@ -139,19 +141,52 @@ describe('Job', function () {
139
141
  done();
140
142
  }
141
143
  };
142
-
143
144
  var j = new _Job["default"](fn);
144
145
  j.idle('first');
145
146
  j.idle('second');
146
147
  jest.runAllTimers();
147
148
  });
149
+ test('should start job when it cannot request idle callback', function (done) {
150
+ var backup = window.requestIdleCallback;
151
+ window.requestIdleCallback = null;
152
+ var j = new _Job["default"](done, 0);
153
+ j.idle();
154
+ jest.runAllTimers();
155
+ window.requestIdleCallback = backup;
156
+ });
157
+ });
158
+ describe('#startRaf', function () {
159
+ test('should start job', function (done) {
160
+ var j = new _Job["default"](done, 10);
161
+ j.startRaf();
162
+ jest.runAllTimers();
163
+ });
164
+ test('should pass args to fn', function (done) {
165
+ var value = 'argument';
166
+ var fn = function fn(arg) {
167
+ if (arg === value) {
168
+ done();
169
+ } else {
170
+ done(new Error('fn did not receive argument'));
171
+ }
172
+ };
173
+ var j = new _Job["default"](fn, 10);
174
+ j.startRaf(value);
175
+ jest.runAllTimers();
176
+ });
177
+ test('should start job immediately when window is not defined', function (done) {
178
+ function returnsUndefined() {}
179
+ var windowSpy = jest.spyOn(window, 'window', 'get').mockImplementation(returnsUndefined);
180
+ var j = new _Job["default"](done, 0);
181
+ j.startRaf();
182
+ windowSpy.mockRestore();
183
+ });
148
184
  });
149
185
  describe('#promise', function () {
150
186
  test('should throw when passed a non-thenable argument', function (done) {
151
187
  var j = new _Job["default"](function () {
152
188
  return done(new Error('Unexpected job execution'));
153
189
  });
154
-
155
190
  try {
156
191
  j.promise({});
157
192
  } catch (msg) {
@@ -162,7 +197,6 @@ describe('Job', function () {
162
197
  var j = new _Job["default"](function () {
163
198
  return done();
164
199
  });
165
-
166
200
  try {
167
201
  j.promise({
168
202
  then: function then(fn) {