@enact/core 4.1.2 → 4.1.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.
- package/CHANGELOG.md +4 -0
- package/README.md +1 -1
- package/dispatcher/tests/dispatcher-specs.js +6 -13
- package/handle/tests/handle-specs.js +21 -29
- package/hoc/hoc.d.ts +2 -1
- package/hoc/tests/hoc-specs.js +67 -30
- package/internal/ApiDecorator/tests/ApiDecorator-specs.js +18 -12
- package/internal/Registry/tests/Registry-specs.js +65 -39
- package/kind/tests/kind-specs.js +52 -30
- package/package.json +8 -8
- package/snapshot/snapshot.d.ts +4 -2
- package/useChainRefs/tests/useChainRefs-specs.js +8 -6
- package/useClass/tests/useClass-specs.js +24 -15
- package/useHandlers/tests/useHandlers-specs.js +40 -26
- package/util/util.d.ts +4 -4
package/CHANGELOG.md
CHANGED
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
|
|
|
@@ -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
|
});
|
|
@@ -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
|
|
|
@@ -15,81 +17,116 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
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
|
});
|
|
@@ -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
|
|
|
@@ -33,6 +33,7 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
|
|
|
33
33
|
describe('ApiDecorator', function () {
|
|
34
34
|
var _class, _temp;
|
|
35
35
|
|
|
36
|
+
var data = [];
|
|
36
37
|
var ApiProvider = (_temp = _class = /*#__PURE__*/function (_ReactComponent) {
|
|
37
38
|
_inherits(ApiProvider, _ReactComponent);
|
|
38
39
|
|
|
@@ -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', _temp);
|
|
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
|
});
|
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
var _react = require("react");
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
require("@testing-library/jest-dom");
|
|
6
|
+
|
|
7
|
+
var _react2 = require("@testing-library/react");
|
|
8
|
+
|
|
9
|
+
var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
|
|
6
10
|
|
|
7
11
|
var _Registry = _interopRequireDefault(require("../Registry"));
|
|
8
12
|
|
|
@@ -144,75 +148,97 @@ describe('Registry', function () {
|
|
|
144
148
|
|
|
145
149
|
HandlesNotification.contextType = SomeContext;
|
|
146
150
|
test('should increment child on click', function () {
|
|
147
|
-
|
|
148
|
-
|
|
151
|
+
(0, _react2.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(NotifiesTree, {
|
|
152
|
+
"data-testid": "a-btn",
|
|
149
153
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(HandlesNotification, {
|
|
150
|
-
|
|
154
|
+
"data-testid": "a"
|
|
151
155
|
})
|
|
152
156
|
}));
|
|
153
|
-
|
|
157
|
+
|
|
158
|
+
_userEvent["default"].click(_react2.screen.getByTestId('a-btn'));
|
|
159
|
+
|
|
154
160
|
var expected = '1';
|
|
155
|
-
|
|
156
|
-
|
|
161
|
+
|
|
162
|
+
var child = _react2.screen.getByTestId('a');
|
|
163
|
+
|
|
164
|
+
expect(child).toHaveTextContent(expected);
|
|
157
165
|
});
|
|
158
166
|
test('should increment both children on top click', function () {
|
|
159
|
-
|
|
160
|
-
|
|
167
|
+
(0, _react2.render)( /*#__PURE__*/(0, _jsxRuntime.jsxs)(NotifiesTree, {
|
|
168
|
+
"data-testid": "a-btn",
|
|
161
169
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(HandlesNotification, {
|
|
162
|
-
|
|
170
|
+
"data-testid": "a"
|
|
163
171
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(NotifiesTree, {
|
|
164
|
-
|
|
172
|
+
"data-testid": "b-btn",
|
|
165
173
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(HandlesNotification, {
|
|
166
|
-
|
|
174
|
+
"data-testid": "b"
|
|
167
175
|
})
|
|
168
176
|
})]
|
|
169
177
|
}));
|
|
170
|
-
|
|
178
|
+
|
|
179
|
+
_userEvent["default"].click(_react2.screen.getByTestId('a-btn'));
|
|
180
|
+
|
|
171
181
|
var expected = '1';
|
|
172
|
-
|
|
173
|
-
var
|
|
174
|
-
|
|
175
|
-
|
|
182
|
+
|
|
183
|
+
var childA = _react2.screen.getByTestId('a');
|
|
184
|
+
|
|
185
|
+
var childB = _react2.screen.getByTestId('b');
|
|
186
|
+
|
|
187
|
+
expect(childA).toHaveTextContent(expected);
|
|
188
|
+
expect(childB).toHaveTextContent(expected);
|
|
176
189
|
});
|
|
177
190
|
test('should increment the deepest child when we click child button', function () {
|
|
178
|
-
|
|
179
|
-
|
|
191
|
+
(0, _react2.render)( /*#__PURE__*/(0, _jsxRuntime.jsxs)(NotifiesTree, {
|
|
192
|
+
"data-testid": "a-btn",
|
|
180
193
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(HandlesNotification, {
|
|
181
|
-
|
|
194
|
+
"data-testid": "a"
|
|
182
195
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(NotifiesTree, {
|
|
183
|
-
|
|
196
|
+
"data-testid": "b-btn",
|
|
184
197
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(HandlesNotification, {
|
|
185
|
-
|
|
198
|
+
"data-testid": "b"
|
|
186
199
|
})
|
|
187
200
|
})]
|
|
188
201
|
}));
|
|
189
|
-
|
|
202
|
+
|
|
203
|
+
_userEvent["default"].click(_react2.screen.getByTestId('b-btn'));
|
|
204
|
+
|
|
190
205
|
var expectedA = '0';
|
|
191
206
|
var expectedB = '1';
|
|
192
|
-
|
|
193
|
-
var
|
|
194
|
-
|
|
195
|
-
|
|
207
|
+
|
|
208
|
+
var childA = _react2.screen.getByTestId('a');
|
|
209
|
+
|
|
210
|
+
var childB = _react2.screen.getByTestId('b');
|
|
211
|
+
|
|
212
|
+
expect(childA).toHaveTextContent(expectedA);
|
|
213
|
+
expect(childB).toHaveTextContent(expectedB);
|
|
196
214
|
});
|
|
197
215
|
test('should support removing children without error', function () {
|
|
198
|
-
var
|
|
199
|
-
|
|
216
|
+
var _render = (0, _react2.render)( /*#__PURE__*/(0, _jsxRuntime.jsxs)(NotifiesTree, {
|
|
217
|
+
"data-testid": "a-btn",
|
|
200
218
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(HandlesNotification, {
|
|
201
|
-
|
|
219
|
+
"data-testid": "a"
|
|
202
220
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(HandlesNotification, {
|
|
203
|
-
|
|
221
|
+
"data-testid": "b"
|
|
204
222
|
})]
|
|
205
|
-
}))
|
|
206
|
-
|
|
223
|
+
})),
|
|
224
|
+
rerender = _render.rerender;
|
|
225
|
+
|
|
226
|
+
_userEvent["default"].click(_react2.screen.getByTestId('a-btn')); // changing children should be safe and not throw errors when notifying instances
|
|
207
227
|
|
|
208
|
-
|
|
228
|
+
|
|
229
|
+
rerender( /*#__PURE__*/(0, _jsxRuntime.jsx)(NotifiesTree, {
|
|
230
|
+
"data-testid": "a-btn",
|
|
209
231
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(HandlesNotification, {
|
|
210
|
-
|
|
232
|
+
"data-testid": "c"
|
|
211
233
|
})
|
|
212
|
-
});
|
|
213
|
-
|
|
234
|
+
}));
|
|
235
|
+
|
|
236
|
+
_userEvent["default"].click(_react2.screen.getByTestId('a-btn'));
|
|
237
|
+
|
|
214
238
|
var expectedC = '1';
|
|
215
|
-
|
|
216
|
-
|
|
239
|
+
|
|
240
|
+
var childC = _react2.screen.getByTestId('c');
|
|
241
|
+
|
|
242
|
+
expect(childC).toHaveTextContent(expectedC);
|
|
217
243
|
});
|
|
218
244
|
});
|
package/kind/tests/kind-specs.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
require("@testing-library/jest-dom");
|
|
4
|
+
|
|
5
|
+
var _react = require("@testing-library/react");
|
|
6
|
+
|
|
7
|
+
var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
|
|
4
8
|
|
|
5
9
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
6
10
|
|
|
7
|
-
var
|
|
11
|
+
var _react2 = require("react");
|
|
8
12
|
|
|
9
13
|
var _kind = _interopRequireDefault(require("../kind"));
|
|
10
14
|
|
|
@@ -35,7 +39,7 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
|
|
|
35
39
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
36
40
|
|
|
37
41
|
describe('kind', function () {
|
|
38
|
-
var TestContext = /*#__PURE__*/(0,
|
|
42
|
+
var TestContext = /*#__PURE__*/(0, _react2.createContext)({
|
|
39
43
|
value: 'initial'
|
|
40
44
|
});
|
|
41
45
|
var Kind = (0, _kind["default"])({
|
|
@@ -73,8 +77,8 @@ describe('kind', function () {
|
|
|
73
77
|
|
|
74
78
|
delete rest.prop;
|
|
75
79
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread(_objectSpread({}, rest), {}, {
|
|
76
|
-
title: label,
|
|
77
80
|
"data-context": contextValue,
|
|
81
|
+
title: label,
|
|
78
82
|
children: value
|
|
79
83
|
}));
|
|
80
84
|
}
|
|
@@ -88,12 +92,16 @@ describe('kind', function () {
|
|
|
88
92
|
var Minimal = (0, _kind["default"])({
|
|
89
93
|
name: 'Minimal',
|
|
90
94
|
render: function render() {
|
|
91
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
95
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
96
|
+
"data-testid": "minimal"
|
|
97
|
+
});
|
|
92
98
|
}
|
|
93
99
|
});
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
100
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Minimal, {}));
|
|
101
|
+
|
|
102
|
+
var minimalDiv = _react.screen.queryByTestId('minimal');
|
|
103
|
+
|
|
104
|
+
expect(minimalDiv).toBeInTheDocument();
|
|
97
105
|
});
|
|
98
106
|
test('should default {label} property', function () {
|
|
99
107
|
var subject = /*#__PURE__*/(0, _jsxRuntime.jsx)(Kind, {
|
|
@@ -107,47 +115,57 @@ describe('kind', function () {
|
|
|
107
115
|
// Explicitly testing for undefined
|
|
108
116
|
// eslint-disable-next-line no-undefined
|
|
109
117
|
var subject = /*#__PURE__*/(0, _jsxRuntime.jsx)(Kind, {
|
|
110
|
-
|
|
111
|
-
|
|
118
|
+
label: undefined,
|
|
119
|
+
prop: 1
|
|
112
120
|
});
|
|
113
121
|
var expected = 'Label';
|
|
114
122
|
var actual = subject.props.label;
|
|
115
123
|
expect(actual).toBe(expected);
|
|
116
124
|
});
|
|
117
125
|
test('should add className defined in styles', function () {
|
|
118
|
-
|
|
126
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Kind, {
|
|
119
127
|
prop: 1
|
|
120
128
|
}));
|
|
121
129
|
var expected = 'kind';
|
|
122
|
-
|
|
123
|
-
|
|
130
|
+
|
|
131
|
+
var kindDiv = _react.screen.getByTitle('Label');
|
|
132
|
+
|
|
133
|
+
expect(kindDiv).toHaveClass(expected);
|
|
124
134
|
});
|
|
125
135
|
test('should compute {value} property', function () {
|
|
126
|
-
|
|
136
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Kind, {
|
|
127
137
|
prop: 1
|
|
128
138
|
}));
|
|
129
|
-
var expected = 2;
|
|
130
|
-
|
|
131
|
-
|
|
139
|
+
var expected = '2';
|
|
140
|
+
|
|
141
|
+
var kindDiv = _react.screen.getByTitle('Label');
|
|
142
|
+
|
|
143
|
+
expect(kindDiv).toHaveTextContent(expected);
|
|
132
144
|
});
|
|
133
145
|
test('should support contextType in handlers', function () {
|
|
134
146
|
var onClick = jest.fn();
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
147
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Kind, {
|
|
148
|
+
onClick: onClick,
|
|
149
|
+
prop: 1
|
|
138
150
|
}));
|
|
139
|
-
|
|
151
|
+
|
|
152
|
+
var kindDiv = _react.screen.getByTitle('Label');
|
|
153
|
+
|
|
154
|
+
_userEvent["default"].click(kindDiv);
|
|
155
|
+
|
|
140
156
|
var expected = 'initial';
|
|
141
157
|
var actual = onClick.mock.calls[0][0];
|
|
142
158
|
expect(actual).toBe(expected);
|
|
143
159
|
});
|
|
144
160
|
test('should support contextType in computed', function () {
|
|
145
|
-
|
|
161
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Kind, {
|
|
146
162
|
prop: 1
|
|
147
163
|
}));
|
|
148
164
|
var expected = 'contextinitial';
|
|
149
|
-
|
|
150
|
-
|
|
165
|
+
|
|
166
|
+
var kindDiv = _react.screen.getByTitle('Label');
|
|
167
|
+
|
|
168
|
+
expect(kindDiv).toHaveAttribute('data-context', expected);
|
|
151
169
|
});
|
|
152
170
|
test('support using hooks within kind instances', function () {
|
|
153
171
|
var Comp = (0, _kind["default"])({
|
|
@@ -155,12 +173,13 @@ describe('kind', function () {
|
|
|
155
173
|
functional: true,
|
|
156
174
|
render: function render() {
|
|
157
175
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
158
|
-
var _useState = (0,
|
|
176
|
+
var _useState = (0, _react2.useState)(0),
|
|
159
177
|
_useState2 = _slicedToArray(_useState, 2),
|
|
160
178
|
state = _useState2[0],
|
|
161
179
|
setState = _useState2[1];
|
|
162
180
|
|
|
163
181
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("button", {
|
|
182
|
+
"data-testid": "button",
|
|
164
183
|
onClick: function onClick() {
|
|
165
184
|
return setState(state + 1);
|
|
166
185
|
},
|
|
@@ -168,11 +187,14 @@ describe('kind', function () {
|
|
|
168
187
|
});
|
|
169
188
|
}
|
|
170
189
|
});
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
var
|
|
174
|
-
|
|
175
|
-
|
|
190
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Comp, {}));
|
|
191
|
+
|
|
192
|
+
var button = _react.screen.getByTestId('button');
|
|
193
|
+
|
|
194
|
+
_userEvent["default"].click(button);
|
|
195
|
+
|
|
196
|
+
var expected = '1';
|
|
197
|
+
expect(button).toHaveTextContent(expected);
|
|
176
198
|
});
|
|
177
199
|
describe('inline', function () {
|
|
178
200
|
test('should support a minimal kind', function () {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@enact/core",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.3",
|
|
4
4
|
"description": "Enact is an open source JavaScript framework containing everything you need to create a fast, scalable mobile or web application.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -25,13 +25,13 @@
|
|
|
25
25
|
}
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"classnames": "^2.
|
|
29
|
-
"invariant": "^2.2.
|
|
30
|
-
"prop-types": "^15.
|
|
31
|
-
"ramda": "^0.
|
|
32
|
-
"react": "^17.0.
|
|
33
|
-
"react-dom": "^17.0.
|
|
34
|
-
"react-is": "^17.0.
|
|
28
|
+
"classnames": "^2.3.1",
|
|
29
|
+
"invariant": "^2.2.4",
|
|
30
|
+
"prop-types": "^15.8.0",
|
|
31
|
+
"ramda": "^0.27.1",
|
|
32
|
+
"react": "^17.0.2",
|
|
33
|
+
"react-dom": "^17.0.2",
|
|
34
|
+
"react-is": "^17.0.2",
|
|
35
35
|
"warning": "^4.0.3"
|
|
36
36
|
}
|
|
37
37
|
}
|
package/snapshot/snapshot.d.ts
CHANGED
|
@@ -16,9 +16,11 @@ and is executed in order once the window is available.
|
|
|
16
16
|
*
|
|
17
17
|
* _Important Notes_
|
|
18
18
|
* * The callback should not alter the initial HTML state. If it does, it will invalidate the
|
|
19
|
-
|
|
19
|
+
*
|
|
20
|
+
* pre-render state and interfere with React rehydration.
|
|
20
21
|
* * The callback should be limited to module-scoped actions and not component instance actions. If
|
|
21
|
-
|
|
22
|
+
*
|
|
23
|
+
* the action is tied to a component, it should be invoked from within the component's lifecycle
|
|
22
24
|
methods.
|
|
23
25
|
*/
|
|
24
26
|
export function onWindowReady(callback: Function): void;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
require("@testing-library/jest-dom");
|
|
4
4
|
|
|
5
|
-
var _react = require("react");
|
|
5
|
+
var _react = require("@testing-library/react");
|
|
6
|
+
|
|
7
|
+
var _react2 = require("react");
|
|
6
8
|
|
|
7
9
|
var _useChainRefs = _interopRequireDefault(require("../useChainRefs"));
|
|
8
10
|
|
|
@@ -33,14 +35,14 @@ describe('useChainRefs', function () {
|
|
|
33
35
|
|
|
34
36
|
test('should call a single functional ref', function () {
|
|
35
37
|
var ref = jest.fn();
|
|
36
|
-
(0,
|
|
38
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
37
39
|
refs: [ref]
|
|
38
40
|
}));
|
|
39
41
|
expect(ref).toHaveBeenCalledTimes(1);
|
|
40
42
|
});
|
|
41
43
|
test('should call a single object ref', function () {
|
|
42
|
-
var ref = /*#__PURE__*/(0,
|
|
43
|
-
(0,
|
|
44
|
+
var ref = /*#__PURE__*/(0, _react2.createRef)();
|
|
45
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
44
46
|
refs: [ref]
|
|
45
47
|
}));
|
|
46
48
|
var expected = 'DIV';
|
|
@@ -50,7 +52,7 @@ describe('useChainRefs', function () {
|
|
|
50
52
|
test('should ignore invalid refs', function () {
|
|
51
53
|
var invalid = {};
|
|
52
54
|
var ref = jest.fn();
|
|
53
|
-
(0,
|
|
55
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
54
56
|
refs: [invalid, ref]
|
|
55
57
|
}));
|
|
56
58
|
expect(ref).toHaveBeenCalledTimes(1);
|
|
@@ -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 _useClass = _interopRequireDefault(require("../useClass"));
|
|
6
8
|
|
|
@@ -20,32 +22,39 @@ describe('useClass', function () {
|
|
|
20
22
|
function Component(props) {
|
|
21
23
|
var instance = (0, _useClass["default"])(Class, props.arg);
|
|
22
24
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
"data-testid": "div",
|
|
26
|
+
"data-fromclass": instance.arg,
|
|
27
|
+
"data-fromprops": props.arg
|
|
25
28
|
});
|
|
26
29
|
}
|
|
27
30
|
|
|
28
31
|
test('should pass arg to Class', function () {
|
|
29
32
|
var arg = 'arg';
|
|
30
|
-
|
|
33
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
31
34
|
arg: arg
|
|
32
35
|
}));
|
|
33
|
-
|
|
34
|
-
var
|
|
35
|
-
|
|
36
|
+
|
|
37
|
+
var div = _react.screen.getByTestId('div');
|
|
38
|
+
|
|
39
|
+
expect(div).toHaveAttribute('data-fromclass', arg);
|
|
36
40
|
});
|
|
37
41
|
test('should use the same instance of Class across renders', function () {
|
|
38
42
|
var arg = 'arg';
|
|
39
|
-
|
|
43
|
+
|
|
44
|
+
var _render = (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
40
45
|
arg: arg
|
|
41
|
-
}))
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
+
})),
|
|
47
|
+
rerender = _render.rerender;
|
|
48
|
+
|
|
49
|
+
var div = _react.screen.getByTestId('div');
|
|
50
|
+
|
|
51
|
+
expect(div).toHaveAttribute('data-fromprops', arg);
|
|
52
|
+
rerender( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
53
|
+
arg: "changed"
|
|
54
|
+
})); // verify that the children still reflects the class value set at construction but the prop
|
|
46
55
|
// value was updated when props were updated
|
|
47
56
|
|
|
48
|
-
expect(
|
|
49
|
-
expect(
|
|
57
|
+
expect(div).toHaveAttribute('data-fromclass', arg);
|
|
58
|
+
expect(div).toHaveAttribute('data-fromprops', 'changed');
|
|
50
59
|
});
|
|
51
60
|
});
|
|
@@ -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 _useHandlers = _interopRequireDefault(require("../useHandlers"));
|
|
6
8
|
|
|
@@ -15,6 +17,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
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('useHandlers', function () {
|
|
20
|
+
var data = {};
|
|
18
21
|
var context = {
|
|
19
22
|
value: 1
|
|
20
23
|
};
|
|
@@ -25,49 +28,61 @@ describe('useHandlers', function () {
|
|
|
25
28
|
return ev(p, c);
|
|
26
29
|
}
|
|
27
30
|
}, props, context);
|
|
28
|
-
|
|
31
|
+
data = {
|
|
32
|
+
handlers: handlers
|
|
33
|
+
};
|
|
34
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread(_objectSpread({}, props), {}, {
|
|
35
|
+
"data-testid": "divComponent"
|
|
36
|
+
}));
|
|
29
37
|
} // Sanity test for Component moreso than useHandlers test
|
|
30
38
|
|
|
31
39
|
|
|
32
40
|
test('should include handlers in props', function () {
|
|
33
|
-
|
|
34
|
-
var
|
|
35
|
-
|
|
36
|
-
expect(actual).toHaveProperty(expected);
|
|
41
|
+
(0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {}));
|
|
42
|
+
var actual = data.handlers.testEvent;
|
|
43
|
+
expect(actual).toBeDefined();
|
|
37
44
|
});
|
|
38
45
|
test('should have the same reference across renders', function () {
|
|
39
|
-
var
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
var
|
|
46
|
+
var _render = (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {})),
|
|
47
|
+
rerender = _render.rerender;
|
|
48
|
+
|
|
49
|
+
var expected = data.handlers.testEvent;
|
|
50
|
+
rerender( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {}));
|
|
51
|
+
var actual = data.handlers.testEvent;
|
|
43
52
|
expect(actual).toBe(expected);
|
|
44
53
|
});
|
|
45
54
|
test('should receive the event', function () {
|
|
46
55
|
var spy = jest.fn();
|
|
47
|
-
|
|
48
|
-
var
|
|
56
|
+
|
|
57
|
+
var _render2 = (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {})),
|
|
58
|
+
rerender = _render2.rerender;
|
|
59
|
+
|
|
60
|
+
rerender( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
49
61
|
children: 'updated'
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
subject.find('div').invoke('testEvent')(spy);
|
|
62
|
+
}));
|
|
63
|
+
data.handlers.testEvent(spy);
|
|
53
64
|
expect(spy).toHaveBeenCalled();
|
|
54
65
|
});
|
|
55
66
|
test('should reflect the latest props', function () {
|
|
56
67
|
var spy = jest.fn();
|
|
57
|
-
|
|
58
|
-
var
|
|
68
|
+
|
|
69
|
+
var _render3 = (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {})),
|
|
70
|
+
rerender = _render3.rerender;
|
|
71
|
+
|
|
72
|
+
rerender( /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
|
|
73
|
+
children: 'updated'
|
|
74
|
+
}));
|
|
75
|
+
data.handlers.testEvent(spy);
|
|
76
|
+
var expected = {
|
|
59
77
|
children: 'updated'
|
|
60
78
|
};
|
|
61
|
-
subject.setProps(props);
|
|
62
|
-
subject.find('div').invoke('testEvent')(spy);
|
|
63
|
-
var expected = props;
|
|
64
79
|
var actual = spy.mock.calls[0][0];
|
|
65
80
|
expect(actual).toMatchObject(expected);
|
|
66
81
|
});
|
|
67
82
|
test('should support component-driven context', function () {
|
|
68
83
|
var spy = jest.fn();
|
|
69
|
-
|
|
70
|
-
|
|
84
|
+
(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
|
|
71
86
|
// expected use case of this feature.
|
|
72
87
|
|
|
73
88
|
var expected = context;
|
|
@@ -78,12 +93,11 @@ describe('useHandlers', function () {
|
|
|
78
93
|
var spy = jest.fn().mockImplementation(function () {
|
|
79
94
|
return 'ok';
|
|
80
95
|
});
|
|
81
|
-
|
|
82
|
-
var returnValue =
|
|
96
|
+
(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
|
|
83
98
|
// expected use case of this feature.
|
|
84
99
|
|
|
85
100
|
var expected = 'ok';
|
|
86
|
-
|
|
87
|
-
expect(actual).toBe(expected);
|
|
101
|
+
expect(returnValue).toBe(expected);
|
|
88
102
|
});
|
|
89
103
|
});
|
package/util/util.d.ts
CHANGED
|
@@ -8,10 +8,10 @@ type Merge<M, N> = Omit<M, Extract<keyof M, keyof N>> & N;
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
export declare class Job {
|
|
11
|
-
constructor
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
constructor
|
|
12
|
+
/**
|
|
13
|
+
* Function to execute as the requested job.
|
|
14
|
+
*/(
|
|
15
15
|
fn: Function
|
|
16
16
|
/**
|
|
17
17
|
* The number of milliseconds to wait before starting the job.
|