@enact/core 4.1.2 → 4.5.0-alpha.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.
- package/CHANGELOG.md +12 -0
- package/README.md +1 -1
- package/dispatcher/listeners.js +1 -1
- package/dispatcher/tests/dispatcher-specs.js +6 -13
- package/handle/handle.js +1 -1
- package/handle/tests/handle-specs.js +23 -31
- package/hoc/hoc.d.ts +2 -1
- package/hoc/tests/hoc-specs.js +69 -32
- package/internal/ApiDecorator/ApiDecorator.js +10 -10
- package/internal/ApiDecorator/tests/ApiDecorator-specs.js +23 -17
- package/internal/Registry/Registry.js +1 -1
- package/internal/Registry/tests/Registry-specs.js +70 -44
- package/keymap/tests/keymap-specs.js +2 -2
- package/kind/computed.js +1 -1
- package/kind/kind.js +8 -8
- package/kind/tests/kind-specs.js +58 -34
- package/package.json +8 -8
- package/platform/platform.js +2 -2
- package/snapshot/snapshot.d.ts +4 -2
- package/snapshot/snapshot.js +2 -2
- package/useChainRefs/tests/useChainRefs-specs.js +8 -6
- package/useChainRefs/useChainRefs.js +1 -1
- package/useClass/tests/useClass-specs.js +30 -17
- package/useClass/useClass.js +1 -1
- package/useHandlers/Handlers.js +2 -2
- package/useHandlers/tests/useHandlers-specs.js +42 -28
- package/useHandlers/useHandlers.js +1 -1
- package/util/Job.js +3 -3
- package/util/tests/Job-specs.js +0 -1
- package/util/util.d.ts +4 -4
- package/util/util.js +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
The following is a curated list of changes in the Enact core module, newest changes on the top.
|
|
4
4
|
|
|
5
|
+
## [4.5.0-alpha.1] - 2022-04-15
|
|
6
|
+
|
|
7
|
+
No significant changes.
|
|
8
|
+
|
|
9
|
+
## [4.1.4] - 2022-03-24
|
|
10
|
+
|
|
11
|
+
No significant changes.
|
|
12
|
+
|
|
13
|
+
## [4.1.3] - 2022-03-07
|
|
14
|
+
|
|
15
|
+
No significant changes.
|
|
16
|
+
|
|
5
17
|
## [4.1.2] - 2021-12-22
|
|
6
18
|
|
|
7
19
|
No significant changes.
|
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ npm test
|
|
|
24
24
|
|
|
25
25
|
Unless otherwise specified, all content, including all source code files and documentation files in this repository are:
|
|
26
26
|
|
|
27
|
-
Copyright (c) 2012-
|
|
27
|
+
Copyright (c) 2012-2022 LG Electronics
|
|
28
28
|
|
|
29
29
|
Unless otherwise specified or set forth in the NOTICE file, all content, including all source code files and documentation files in this repository are: Licensed under the Apache License, Version 2.0 (the "License"); you may not use this content except in compliance with the License. You may obtain a copy of the License at
|
|
30
30
|
|
package/dispatcher/listeners.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.getListeners = exports["default"] = exports.addListener = void 0;
|
|
7
7
|
// Simple Map polyfill mapping targets to a hash of names->handler[]
|
|
8
8
|
var targets = [];
|
|
9
9
|
var events = [];
|
|
@@ -9,8 +9,7 @@ describe('dispatcher', function () {
|
|
|
9
9
|
var ev = new window.CustomEvent('localechange', {});
|
|
10
10
|
window.dispatchEvent(ev);
|
|
11
11
|
var expected = 1;
|
|
12
|
-
|
|
13
|
-
expect(actual).toBe(expected);
|
|
12
|
+
expect(handler).toHaveBeenCalledTimes(expected);
|
|
14
13
|
});
|
|
15
14
|
test('should not register duplicate handlers on target', function () {
|
|
16
15
|
var handler = jest.fn();
|
|
@@ -19,8 +18,7 @@ describe('dispatcher', function () {
|
|
|
19
18
|
var ev = new window.CustomEvent('localechange', {});
|
|
20
19
|
window.dispatchEvent(ev);
|
|
21
20
|
var expected = 1;
|
|
22
|
-
|
|
23
|
-
expect(actual).toBe(expected);
|
|
21
|
+
expect(handler).toHaveBeenCalledTimes(expected);
|
|
24
22
|
});
|
|
25
23
|
test('should unregister handlers on target', function () {
|
|
26
24
|
var handler = jest.fn();
|
|
@@ -30,8 +28,7 @@ describe('dispatcher', function () {
|
|
|
30
28
|
(0, _dispatcher.off)('localechange', handler, window);
|
|
31
29
|
window.dispatchEvent(ev);
|
|
32
30
|
var expected = 1;
|
|
33
|
-
|
|
34
|
-
expect(actual).toBe(expected);
|
|
31
|
+
expect(handler).toHaveBeenCalledTimes(expected);
|
|
35
32
|
});
|
|
36
33
|
test('should only call a "once" handler once', function () {
|
|
37
34
|
var handler = jest.fn();
|
|
@@ -40,8 +37,7 @@ describe('dispatcher', function () {
|
|
|
40
37
|
window.dispatchEvent(ev);
|
|
41
38
|
window.dispatchEvent(ev);
|
|
42
39
|
var expected = 1;
|
|
43
|
-
|
|
44
|
-
expect(actual).toBe(expected);
|
|
40
|
+
expect(handler).toHaveBeenCalledTimes(expected);
|
|
45
41
|
});
|
|
46
42
|
test('should allow unregistering a "once" before it is called', function () {
|
|
47
43
|
var handler = jest.fn();
|
|
@@ -49,9 +45,7 @@ describe('dispatcher', function () {
|
|
|
49
45
|
(0, _dispatcher.off)('localechange', onceHandler, window);
|
|
50
46
|
var ev = new window.CustomEvent('localechange', {});
|
|
51
47
|
window.dispatchEvent(ev);
|
|
52
|
-
|
|
53
|
-
var actual = handler.mock.calls.length;
|
|
54
|
-
expect(actual).toBe(expected);
|
|
48
|
+
expect(handler).not.toHaveBeenCalled();
|
|
55
49
|
});
|
|
56
50
|
test('should not block subsequent handlers when a handler throws', function () {
|
|
57
51
|
// Modify the console spy to silence error output with
|
|
@@ -69,7 +63,6 @@ describe('dispatcher', function () {
|
|
|
69
63
|
var ev = new window.CustomEvent('localechange', {});
|
|
70
64
|
window.dispatchEvent(ev);
|
|
71
65
|
var expected = 1;
|
|
72
|
-
|
|
73
|
-
expect(actual).toBe(expected);
|
|
66
|
+
expect(handler).toHaveBeenCalledTimes(expected);
|
|
74
67
|
});
|
|
75
68
|
});
|
package/handle/handle.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.stopImmediate = exports.stop = exports.returnsTrue = exports.preventDefault = exports.oneOf = exports.not = exports.log = exports.handle = exports.
|
|
6
|
+
exports.stopImmediate = exports.stop = exports.returnsTrue = exports.preventDefault = exports.oneOf = exports.not = exports.log = exports.handle = exports.forwardWithPrevent = exports.forwardCustom = exports.forward = exports.forProp = exports.forKeyCode = exports.forKey = exports.forEventProp = exports["default"] = exports.callOnEvent = exports.call = exports.adaptEvent = void 0;
|
|
7
7
|
|
|
8
8
|
var _cond = _interopRequireDefault(require("ramda/src/cond"));
|
|
9
9
|
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
var _handle = require("../handle");
|
|
4
4
|
|
|
5
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
|
5
|
+
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; }
|
|
6
6
|
|
|
7
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
7
|
+
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; }
|
|
8
8
|
|
|
9
9
|
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; }
|
|
10
10
|
|
|
@@ -29,50 +29,48 @@ describe('handle', function () {
|
|
|
29
29
|
var callback = (0, _handle.handle)(handler);
|
|
30
30
|
callback(makeEvent());
|
|
31
31
|
var expected = 1;
|
|
32
|
-
|
|
33
|
-
expect(actual).toBe(expected);
|
|
32
|
+
expect(handler).toHaveBeenCalledTimes(expected);
|
|
34
33
|
});
|
|
35
34
|
test('should call multiple handlers', function () {
|
|
36
35
|
var handler1 = jest.fn(returnsTrue);
|
|
37
36
|
var handler2 = jest.fn(returnsTrue);
|
|
38
37
|
var callback = (0, _handle.handle)(handler1, handler2);
|
|
39
38
|
callback(makeEvent());
|
|
40
|
-
var expected =
|
|
41
|
-
|
|
42
|
-
expect(
|
|
39
|
+
var expected = 1;
|
|
40
|
+
expect(handler1).toHaveBeenCalledTimes(expected);
|
|
41
|
+
expect(handler2).toHaveBeenCalledTimes(expected);
|
|
43
42
|
});
|
|
44
43
|
test('should skip non-function handlers', function () {
|
|
45
44
|
var handler = jest.fn(returnsTrue);
|
|
46
45
|
var callback = (0, _handle.handle)(null, void 0, 0, 'purple', handler);
|
|
47
46
|
callback(makeEvent());
|
|
48
47
|
var expected = 1;
|
|
49
|
-
|
|
50
|
-
expect(actual).toBe(expected);
|
|
48
|
+
expect(handler).toHaveBeenCalledTimes(expected);
|
|
51
49
|
});
|
|
52
50
|
test('should not call handlers after one that returns false', function () {
|
|
53
51
|
var handler1 = jest.fn(returnsTrue);
|
|
54
52
|
var handler2 = jest.fn(returnsTrue);
|
|
55
53
|
var callback = (0, _handle.handle)(handler1, returnsFalse, handler2);
|
|
56
54
|
callback(makeEvent());
|
|
57
|
-
var
|
|
58
|
-
|
|
59
|
-
expect(
|
|
55
|
+
var expectedFirst = 1;
|
|
56
|
+
expect(handler1).toHaveBeenCalledTimes(expectedFirst);
|
|
57
|
+
expect(handler2).not.toHaveBeenCalled();
|
|
60
58
|
});
|
|
61
59
|
test('should call stopPropagation on event', function () {
|
|
62
60
|
var callback = (0, _handle.handle)(_handle.stop);
|
|
63
61
|
var ev = makeEvent();
|
|
64
62
|
callback(ev);
|
|
65
63
|
var expected = 1;
|
|
66
|
-
var actual = ev.stopPropagation
|
|
67
|
-
expect(actual).
|
|
64
|
+
var actual = ev.stopPropagation;
|
|
65
|
+
expect(actual).toHaveBeenCalledTimes(expected);
|
|
68
66
|
});
|
|
69
67
|
test('should call preventDefault on event', function () {
|
|
70
68
|
var callback = (0, _handle.handle)(_handle.preventDefault);
|
|
71
69
|
var ev = makeEvent();
|
|
72
70
|
callback(ev);
|
|
73
71
|
var expected = 1;
|
|
74
|
-
var actual = ev.preventDefault
|
|
75
|
-
expect(actual).
|
|
72
|
+
var actual = ev.preventDefault;
|
|
73
|
+
expect(actual).toHaveBeenCalledTimes(expected);
|
|
76
74
|
});
|
|
77
75
|
test('should call any method on event', function () {
|
|
78
76
|
var callback = (0, _handle.handle)((0, _handle.callOnEvent)('customMethod'));
|
|
@@ -81,8 +79,8 @@ describe('handle', function () {
|
|
|
81
79
|
});
|
|
82
80
|
callback(ev);
|
|
83
81
|
var expected = 1;
|
|
84
|
-
var actual = ev.customMethod
|
|
85
|
-
expect(actual).
|
|
82
|
+
var actual = ev.customMethod;
|
|
83
|
+
expect(actual).toHaveBeenCalledTimes(expected);
|
|
86
84
|
});
|
|
87
85
|
test('should only call handler for specified keyCode', function () {
|
|
88
86
|
var keyCode = 13;
|
|
@@ -96,9 +94,9 @@ describe('handle', function () {
|
|
|
96
94
|
expect(handler).toHaveBeenCalled();
|
|
97
95
|
});
|
|
98
96
|
test('should only call handler for specified event prop', function () {
|
|
97
|
+
var handler = jest.fn();
|
|
99
98
|
var prop = 'index';
|
|
100
99
|
var value = 0;
|
|
101
|
-
var handler = jest.fn();
|
|
102
100
|
var callback = (0, _handle.handle)((0, _handle.forEventProp)(prop, value), handler); // undefined shouldn't pass
|
|
103
101
|
|
|
104
102
|
callback(makeEvent());
|
|
@@ -201,16 +199,14 @@ describe('handle', function () {
|
|
|
201
199
|
var callback = (0, _handle.handle)(returnsTrue)["finally"](finallyCallback);
|
|
202
200
|
callback(makeEvent());
|
|
203
201
|
var expected = 1;
|
|
204
|
-
|
|
205
|
-
expect(actual).toBe(expected);
|
|
202
|
+
expect(finallyCallback).toHaveBeenCalledTimes(expected);
|
|
206
203
|
});
|
|
207
204
|
test('should call the finally callback when handle returns false', function () {
|
|
208
205
|
var finallyCallback = jest.fn();
|
|
209
206
|
var callback = (0, _handle.handle)(returnsFalse)["finally"](finallyCallback);
|
|
210
207
|
callback(makeEvent());
|
|
211
208
|
var expected = 1;
|
|
212
|
-
|
|
213
|
-
expect(actual).toBe(expected);
|
|
209
|
+
expect(finallyCallback).toHaveBeenCalledTimes(expected);
|
|
214
210
|
});
|
|
215
211
|
test('should call the finally callback when handle throws an error', function () {
|
|
216
212
|
var finallyCallback = jest.fn();
|
|
@@ -224,8 +220,7 @@ describe('handle', function () {
|
|
|
224
220
|
}
|
|
225
221
|
|
|
226
222
|
var expected = 1;
|
|
227
|
-
|
|
228
|
-
expect(actual).toBe(expected);
|
|
223
|
+
expect(finallyCallback).toHaveBeenCalledTimes(expected);
|
|
229
224
|
});
|
|
230
225
|
});
|
|
231
226
|
describe('#oneOf', function () {
|
|
@@ -236,16 +231,14 @@ describe('handle', function () {
|
|
|
236
231
|
var callback = (0, _handle.oneOf)(h1, h1, h2);
|
|
237
232
|
callback();
|
|
238
233
|
var expected = 1;
|
|
239
|
-
|
|
240
|
-
expect(actual).toBe(expected);
|
|
234
|
+
expect(handler).toHaveBeenCalledTimes(expected);
|
|
241
235
|
});
|
|
242
236
|
test('should stop if the first handler passes', function () {
|
|
243
237
|
var handler = jest.fn(returnsTrue);
|
|
244
238
|
var callback = (0, _handle.oneOf)([returnsTrue, handler], [returnsTrue, handler], [returnsTrue, handler]);
|
|
245
239
|
callback();
|
|
246
240
|
var expected = 1;
|
|
247
|
-
|
|
248
|
-
expect(actual).toBe(expected);
|
|
241
|
+
expect(handler).toHaveBeenCalledTimes(expected);
|
|
249
242
|
});
|
|
250
243
|
test('should pass args to condition', function () {
|
|
251
244
|
var handler = jest.fn(returnsTrue);
|
|
@@ -347,8 +340,7 @@ describe('handle', function () {
|
|
|
347
340
|
var callback = (0, _handle.oneOf)([returnsFalse, returnsTrue], [returnsFalse, returnsTrue])["finally"](handler);
|
|
348
341
|
callback();
|
|
349
342
|
var expected = 1;
|
|
350
|
-
|
|
351
|
-
expect(actual).toBe(expected);
|
|
343
|
+
expect(handler).toHaveBeenCalledTimes(expected);
|
|
352
344
|
});
|
|
353
345
|
});
|
|
354
346
|
describe('#adaptEvent', function () {
|
package/hoc/hoc.d.ts
CHANGED
|
@@ -9,7 +9,8 @@ a factory method that accepts instance configuration parameters and a component
|
|
|
9
9
|
returned function can accept:
|
|
10
10
|
* * an instance config and a component constructor to wrap and return a renderable component, or
|
|
11
11
|
* * an instance config only and return a decorator function expecting a component constructor
|
|
12
|
-
|
|
12
|
+
*
|
|
13
|
+
* (like the next bullet), or
|
|
13
14
|
* * a component constructor and return a renderable component
|
|
14
15
|
*
|
|
15
16
|
* Example:
|
package/hoc/tests/hoc-specs.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
require("@testing-library/jest-dom");
|
|
4
|
+
|
|
5
|
+
var _react = require("@testing-library/react");
|
|
4
6
|
|
|
5
7
|
var _hoc = _interopRequireDefault(require("../hoc"));
|
|
6
8
|
|
|
@@ -8,88 +10,123 @@ var _jsxRuntime = require("react/jsx-runtime");
|
|
|
8
10
|
|
|
9
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
10
12
|
|
|
11
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
|
13
|
+
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; }
|
|
12
14
|
|
|
13
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
15
|
+
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; }
|
|
14
16
|
|
|
15
17
|
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; }
|
|
16
18
|
|
|
17
19
|
describe('hoc', function () {
|
|
20
|
+
var data;
|
|
21
|
+
var testID = 'test-HoC';
|
|
18
22
|
var defaultConfig = {
|
|
19
23
|
color: 'blue'
|
|
20
24
|
};
|
|
21
25
|
var HoC = (0, _hoc["default"])(defaultConfig, function (config, Wrapped) {
|
|
26
|
+
data = Wrapped;
|
|
22
27
|
return function (props) {
|
|
23
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Wrapped, _objectSpread(_objectSpread({}, props), config)
|
|
28
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Wrapped, _objectSpread(_objectSpread(_objectSpread({}, props), config), {}, {
|
|
29
|
+
"data-testid": testID
|
|
30
|
+
}));
|
|
24
31
|
};
|
|
25
32
|
});
|
|
26
33
|
var NullHoC = (0, _hoc["default"])(null, function (config, Wrapped) {
|
|
27
34
|
return function () {
|
|
28
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Wrapped, _objectSpread({}, config)
|
|
35
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Wrapped, _objectSpread(_objectSpread({}, config), {}, {
|
|
36
|
+
"data-testid": testID
|
|
37
|
+
}));
|
|
29
38
|
};
|
|
30
39
|
});
|
|
31
40
|
test('should support HoC factory function as first argument to hoc()', function () {
|
|
32
41
|
var ImplicitNullHoC = (0, _hoc["default"])(function (config, Wrapped) {
|
|
33
42
|
return function () {
|
|
34
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Wrapped, _objectSpread({}, config)
|
|
43
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Wrapped, _objectSpread(_objectSpread({}, config), {}, {
|
|
44
|
+
"data-testid": testID
|
|
45
|
+
}));
|
|
35
46
|
};
|
|
36
47
|
});
|
|
37
48
|
var Component = ImplicitNullHoC('span');
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
var
|
|
49
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {}));
|
|
50
|
+
|
|
51
|
+
var component = _react.screen.getByTestId(testID);
|
|
52
|
+
|
|
53
|
+
var expected = 'SPAN';
|
|
54
|
+
var actual = component.nodeName;
|
|
41
55
|
expect(actual).toBe(expected);
|
|
42
56
|
});
|
|
43
57
|
test('should support DOM node name as first argument to HoC', function () {
|
|
44
58
|
var Component = HoC('span');
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
var
|
|
59
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {}));
|
|
60
|
+
|
|
61
|
+
var component = _react.screen.getByTestId(testID);
|
|
62
|
+
|
|
63
|
+
var expected = 'SPAN';
|
|
64
|
+
var actual = component.nodeName;
|
|
48
65
|
expect(actual).toBe(expected);
|
|
49
66
|
});
|
|
50
67
|
test('should support React component as first argument to HoC', function () {
|
|
51
68
|
function Thing() {
|
|
52
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
69
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
70
|
+
"data-testid": testID
|
|
71
|
+
});
|
|
53
72
|
}
|
|
54
73
|
|
|
55
74
|
var Component = HoC(Thing);
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
var
|
|
75
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {}));
|
|
76
|
+
|
|
77
|
+
var component = _react.screen.getByTestId(testID);
|
|
78
|
+
|
|
79
|
+
var expected = 'DIV';
|
|
80
|
+
var actual = component.nodeName;
|
|
81
|
+
var actualWrapped = data;
|
|
59
82
|
expect(actual).toBe(expected);
|
|
83
|
+
expect(actualWrapped).toBe(Thing);
|
|
60
84
|
});
|
|
61
85
|
test('should use default config when instance config is omitted', function () {
|
|
62
86
|
var Component = HoC('span');
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
var
|
|
66
|
-
|
|
87
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {}));
|
|
88
|
+
|
|
89
|
+
var component = _react.screen.getByTestId(testID);
|
|
90
|
+
|
|
91
|
+
var expectedAttribute = 'color';
|
|
92
|
+
var expectedValue = defaultConfig.color;
|
|
93
|
+
expect(component).toHaveAttribute(expectedAttribute, expectedValue);
|
|
67
94
|
});
|
|
68
95
|
test('should overwrite default config with instance config', function () {
|
|
69
96
|
var instanceConfig = {
|
|
70
97
|
color: 'green'
|
|
71
98
|
};
|
|
72
99
|
var Component = HoC(instanceConfig, 'div');
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
var
|
|
76
|
-
|
|
100
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {}));
|
|
101
|
+
|
|
102
|
+
var component = _react.screen.getByTestId(testID);
|
|
103
|
+
|
|
104
|
+
var expectedAttribute = 'color';
|
|
105
|
+
var expectedValue = instanceConfig.color;
|
|
106
|
+
expect(component).toHaveAttribute(expectedAttribute, expectedValue);
|
|
77
107
|
});
|
|
78
108
|
test('should allow construction without default or instance configs', function () {
|
|
79
|
-
var Component = NullHoC('
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
var
|
|
109
|
+
var Component = NullHoC('input');
|
|
110
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {}));
|
|
111
|
+
|
|
112
|
+
var component = _react.screen.getByTestId(testID);
|
|
113
|
+
|
|
114
|
+
var expected = 'INPUT';
|
|
115
|
+
var actual = component.nodeName;
|
|
83
116
|
expect(actual).toBe(expected);
|
|
117
|
+
expect(component).toBeInTheDocument();
|
|
84
118
|
});
|
|
85
119
|
test('should allow construction without default config', function () {
|
|
86
120
|
var instanceConfig = {
|
|
87
121
|
color: 'green'
|
|
88
122
|
};
|
|
89
123
|
var Component = NullHoC(instanceConfig, 'div');
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
var
|
|
93
|
-
|
|
124
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {}));
|
|
125
|
+
|
|
126
|
+
var component = _react.screen.getByTestId(testID);
|
|
127
|
+
|
|
128
|
+
var expectedAttribute = 'color';
|
|
129
|
+
var expectedValue = instanceConfig.color;
|
|
130
|
+
expect(component).toHaveAttribute(expectedAttribute, expectedValue);
|
|
94
131
|
});
|
|
95
132
|
});
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports
|
|
6
|
+
exports["default"] = exports.ApiDecorator = void 0;
|
|
7
7
|
|
|
8
8
|
var _invariant = _interopRequireDefault(require("invariant"));
|
|
9
9
|
|
|
@@ -15,9 +15,9 @@ var _jsxRuntime = require("react/jsx-runtime");
|
|
|
15
15
|
|
|
16
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
17
17
|
|
|
18
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
|
18
|
+
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; }
|
|
19
19
|
|
|
20
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
20
|
+
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; }
|
|
21
21
|
|
|
22
22
|
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; }
|
|
23
23
|
|
|
@@ -25,15 +25,15 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
25
25
|
|
|
26
26
|
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); } }
|
|
27
27
|
|
|
28
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
28
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
29
29
|
|
|
30
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
30
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
31
31
|
|
|
32
32
|
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
33
33
|
|
|
34
34
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
35
35
|
|
|
36
|
-
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
36
|
+
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
37
37
|
|
|
38
38
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
39
39
|
|
|
@@ -100,11 +100,11 @@ var defaultConfig = {
|
|
|
100
100
|
*/
|
|
101
101
|
|
|
102
102
|
var ApiDecorator = (0, _hoc["default"])(defaultConfig, function (config, Wrapped) {
|
|
103
|
-
var _class
|
|
103
|
+
var _class;
|
|
104
104
|
|
|
105
105
|
var api = config.api;
|
|
106
|
-
!(api != null) ? process.env.NODE_ENV !== "production" ? (0, _invariant["default"])(false, 'ApiDecorator: api is a required config property') :
|
|
107
|
-
return
|
|
106
|
+
!(api != null) ? process.env.NODE_ENV !== "production" ? (0, _invariant["default"])(false, 'ApiDecorator: api is a required config property') : (0, _invariant["default"])(false) : void 0;
|
|
107
|
+
return _class = /*#__PURE__*/function (_Component) {
|
|
108
108
|
_inherits(_class, _Component);
|
|
109
109
|
|
|
110
110
|
var _super = _createSuper(_class);
|
|
@@ -144,7 +144,7 @@ var ApiDecorator = (0, _hoc["default"])(defaultConfig, function (config, Wrapped
|
|
|
144
144
|
}]);
|
|
145
145
|
|
|
146
146
|
return _class;
|
|
147
|
-
}(_react.Component), _class.displayName = 'ApiDecorator',
|
|
147
|
+
}(_react.Component), _class.displayName = 'ApiDecorator', _class;
|
|
148
148
|
});
|
|
149
149
|
exports.ApiDecorator = ApiDecorator;
|
|
150
150
|
var _default = ApiDecorator;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _react = require("react");
|
|
3
|
+
var _react = require("@testing-library/react");
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _react2 = require("react");
|
|
6
6
|
|
|
7
7
|
var _ApiDecorator = _interopRequireDefault(require("../ApiDecorator"));
|
|
8
8
|
|
|
@@ -14,15 +14,15 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|
|
14
14
|
|
|
15
15
|
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); } }
|
|
16
16
|
|
|
17
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
17
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
18
18
|
|
|
19
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
19
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
20
20
|
|
|
21
21
|
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
22
22
|
|
|
23
23
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
24
24
|
|
|
25
|
-
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
25
|
+
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
26
26
|
|
|
27
27
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
28
28
|
|
|
@@ -31,9 +31,10 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
31
31
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
32
32
|
|
|
33
33
|
describe('ApiDecorator', function () {
|
|
34
|
-
var _class
|
|
34
|
+
var _class;
|
|
35
35
|
|
|
36
|
-
var
|
|
36
|
+
var data = [];
|
|
37
|
+
var ApiProvider = (_class = /*#__PURE__*/function (_ReactComponent) {
|
|
37
38
|
_inherits(ApiProvider, _ReactComponent);
|
|
38
39
|
|
|
39
40
|
var _super = _createSuper(ApiProvider);
|
|
@@ -62,47 +63,52 @@ describe('ApiDecorator', function () {
|
|
|
62
63
|
}, {
|
|
63
64
|
key: "render",
|
|
64
65
|
value: function render() {
|
|
66
|
+
data = {
|
|
67
|
+
arrowFunction: this.arrowFunction,
|
|
68
|
+
instanceFunction: this.instanceFunction,
|
|
69
|
+
instanceProperty: this.instanceProperty
|
|
70
|
+
};
|
|
65
71
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {});
|
|
66
72
|
}
|
|
67
73
|
}]);
|
|
68
74
|
|
|
69
75
|
return ApiProvider;
|
|
70
|
-
}(
|
|
76
|
+
}(_react2.Component), _class.displayName = 'ApiProvider', _class);
|
|
71
77
|
test('should invoke arrow function on wrapped component', function () {
|
|
72
78
|
var Component = (0, _ApiDecorator["default"])({
|
|
73
79
|
api: ['arrowFunction']
|
|
74
80
|
}, ApiProvider);
|
|
75
|
-
|
|
81
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {}));
|
|
76
82
|
var expected = 'arrow';
|
|
77
|
-
var actual =
|
|
83
|
+
var actual = data.arrowFunction();
|
|
78
84
|
expect(actual).toBe(expected);
|
|
79
85
|
});
|
|
80
86
|
test('should invoke instance function on wrapped component', function () {
|
|
81
87
|
var Component = (0, _ApiDecorator["default"])({
|
|
82
88
|
api: ['instanceFunction']
|
|
83
89
|
}, ApiProvider);
|
|
84
|
-
|
|
90
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {}));
|
|
85
91
|
var expected = 'instance';
|
|
86
|
-
var actual =
|
|
92
|
+
var actual = data.instanceFunction();
|
|
87
93
|
expect(actual).toBe(expected);
|
|
88
94
|
});
|
|
89
95
|
test('should get an instance property on wrapped component', function () {
|
|
90
96
|
var Component = (0, _ApiDecorator["default"])({
|
|
91
97
|
api: ['instanceProperty']
|
|
92
98
|
}, ApiProvider);
|
|
93
|
-
|
|
99
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {}));
|
|
94
100
|
var expected = 'property';
|
|
95
|
-
var actual =
|
|
101
|
+
var actual = data.instanceProperty;
|
|
96
102
|
expect(actual).toBe(expected);
|
|
97
103
|
});
|
|
98
104
|
test('should set an instance property on wrapped component', function () {
|
|
99
105
|
var Component = (0, _ApiDecorator["default"])({
|
|
100
106
|
api: ['instanceProperty']
|
|
101
107
|
}, ApiProvider);
|
|
102
|
-
|
|
103
|
-
|
|
108
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {}));
|
|
109
|
+
data.instanceProperty = 'updated';
|
|
104
110
|
var expected = 'updated';
|
|
105
|
-
var actual =
|
|
111
|
+
var actual = data.instanceProperty;
|
|
106
112
|
expect(actual).toBe(expected);
|
|
107
113
|
});
|
|
108
114
|
});
|