anu-verzum 1.23.2 → 1.23.9
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/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "anu-verzum",
|
|
3
|
-
"version": "1.23.
|
|
3
|
+
"version": "1.23.9",
|
|
4
4
|
"description": "A \"React-like\" UI library that supports JSX syntax, Redux-like state management, array-rendering, i18n, routing and many more.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"anu-verzum",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
39
39
|
"clean": "node -e \"require('fs').rmSync('dist', {recursive:true, force:true})\"",
|
|
40
|
-
"build": "npm run clean && babel src --out-dir dist --extensions \".ts\" && tsc --emitDeclarationOnly",
|
|
40
|
+
"build": "npm run clean && babel src --out-dir dist --extensions \".ts\" --ignore \"src/testing/__tests__\" && tsc --project tsconfig.build.json --emitDeclarationOnly",
|
|
41
41
|
"typecheck": "tsc --noEmit",
|
|
42
42
|
"lint": "eslint src",
|
|
43
43
|
"format": "prettier --write src",
|
|
@@ -49,7 +49,6 @@
|
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"@babel/plugin-transform-react-jsx": "^7.21.0",
|
|
51
51
|
"@babel/plugin-transform-typescript": "^7.28.6",
|
|
52
|
-
"@babel/preset-env": "^7.21.0",
|
|
53
52
|
"babel-loader": "^9.0.0",
|
|
54
53
|
"html-webpack-plugin": "^5.0.0",
|
|
55
54
|
"webpack": "^5.0.0",
|
|
@@ -59,6 +58,7 @@
|
|
|
59
58
|
"devDependencies": {
|
|
60
59
|
"@babel/cli": "^7.21.0",
|
|
61
60
|
"@babel/core": "^7.21.0",
|
|
61
|
+
"@babel/preset-env": "^7.21.0",
|
|
62
62
|
"@babel/preset-typescript": "^7.28.5",
|
|
63
63
|
"@eslint/js": "^10.0.1",
|
|
64
64
|
"@types/jest": "^29.5.14",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _index = _interopRequireWildcard(require("../../index"));
|
|
4
|
-
var _index2 = require("../index");
|
|
5
|
-
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
6
|
-
class Counter extends _index.Component {
|
|
7
|
-
state = {
|
|
8
|
-
count: 0
|
|
9
|
-
};
|
|
10
|
-
render() {
|
|
11
|
-
return _index.default.createElement('div', {}, _index.default.createElement('p', {}, `Count: ${this.state.count}`), _index.default.createElement('button', {
|
|
12
|
-
onClick: () => this.setState({
|
|
13
|
-
count: this.state.count + 1
|
|
14
|
-
})
|
|
15
|
-
}, 'Increment'));
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
const Greeting = ({
|
|
19
|
-
name
|
|
20
|
-
}) => _index.default.createElement('h1', {}, `Hello, ${name}!`);
|
|
21
|
-
describe('render', () => {
|
|
22
|
-
test('renders a function component', () => {
|
|
23
|
-
const {
|
|
24
|
-
getByText
|
|
25
|
-
} = (0, _index2.render)(_index.default.createElement(Greeting, {
|
|
26
|
-
name: 'World'
|
|
27
|
-
}));
|
|
28
|
-
expect(getByText('Hello, World!')).toBeDefined();
|
|
29
|
-
});
|
|
30
|
-
test('renders a class component', () => {
|
|
31
|
-
const {
|
|
32
|
-
getByText
|
|
33
|
-
} = (0, _index2.render)(_index.default.createElement(Counter, {}));
|
|
34
|
-
expect(getByText('Count: 0')).toBeDefined();
|
|
35
|
-
});
|
|
36
|
-
test('returns a container attached to document.body', () => {
|
|
37
|
-
const {
|
|
38
|
-
container
|
|
39
|
-
} = (0, _index2.render)(_index.default.createElement(Greeting, {
|
|
40
|
-
name: 'test'
|
|
41
|
-
}));
|
|
42
|
-
expect(document.body.contains(container)).toBe(true);
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
describe('queries', () => {
|
|
46
|
-
test('getByRole finds button', () => {
|
|
47
|
-
const {
|
|
48
|
-
getByRole
|
|
49
|
-
} = (0, _index2.render)(_index.default.createElement(Counter, {}));
|
|
50
|
-
const btn = getByRole('button');
|
|
51
|
-
expect(btn).toBeDefined();
|
|
52
|
-
expect(btn.textContent).toBe('Increment');
|
|
53
|
-
});
|
|
54
|
-
test('getByRole with name option', () => {
|
|
55
|
-
const {
|
|
56
|
-
getByRole
|
|
57
|
-
} = (0, _index2.render)(_index.default.createElement(Counter, {}));
|
|
58
|
-
const btn = getByRole('button', {
|
|
59
|
-
name: 'Increment'
|
|
60
|
-
});
|
|
61
|
-
expect(btn).toBeDefined();
|
|
62
|
-
});
|
|
63
|
-
test('queryByText returns null when not found', () => {
|
|
64
|
-
const {
|
|
65
|
-
queryByText
|
|
66
|
-
} = (0, _index2.render)(_index.default.createElement(Greeting, {
|
|
67
|
-
name: 'test'
|
|
68
|
-
}));
|
|
69
|
-
expect(queryByText('Not here')).toBeNull();
|
|
70
|
-
});
|
|
71
|
-
test('getByText throws when not found', () => {
|
|
72
|
-
const {
|
|
73
|
-
getByText
|
|
74
|
-
} = (0, _index2.render)(_index.default.createElement(Greeting, {
|
|
75
|
-
name: 'test'
|
|
76
|
-
}));
|
|
77
|
-
expect(() => getByText('Not here')).toThrow();
|
|
78
|
-
});
|
|
79
|
-
test('findByText resolves asynchronously', async () => {
|
|
80
|
-
const {
|
|
81
|
-
findByText
|
|
82
|
-
} = (0, _index2.render)(_index.default.createElement(Greeting, {
|
|
83
|
-
name: 'World'
|
|
84
|
-
}));
|
|
85
|
-
const el = await findByText('Hello, World!');
|
|
86
|
-
expect(el).toBeDefined();
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
describe('fireEvent', () => {
|
|
90
|
-
test('click triggers onClick and re-renders', () => {
|
|
91
|
-
const {
|
|
92
|
-
getByText,
|
|
93
|
-
getByRole
|
|
94
|
-
} = (0, _index2.render)(_index.default.createElement(Counter, {}));
|
|
95
|
-
expect(getByText('Count: 0')).toBeDefined();
|
|
96
|
-
_index2.fireEvent.click(getByRole('button'));
|
|
97
|
-
expect(getByText('Count: 1')).toBeDefined();
|
|
98
|
-
});
|
|
99
|
-
test('multiple clicks accumulate', () => {
|
|
100
|
-
const {
|
|
101
|
-
getByText,
|
|
102
|
-
getByRole
|
|
103
|
-
} = (0, _index2.render)(_index.default.createElement(Counter, {}));
|
|
104
|
-
_index2.fireEvent.click(getByRole('button'));
|
|
105
|
-
_index2.fireEvent.click(getByRole('button'));
|
|
106
|
-
_index2.fireEvent.click(getByRole('button'));
|
|
107
|
-
expect(getByText('Count: 3')).toBeDefined();
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
describe('userEvent', () => {
|
|
111
|
-
test('click fires full mouse event sequence', () => {
|
|
112
|
-
const {
|
|
113
|
-
getByText,
|
|
114
|
-
getByRole
|
|
115
|
-
} = (0, _index2.render)(_index.default.createElement(Counter, {}));
|
|
116
|
-
_index2.userEvent.click(getByRole('button'));
|
|
117
|
-
expect(getByText('Count: 1')).toBeDefined();
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
describe('rerender', () => {
|
|
121
|
-
test('updates the component with new props', () => {
|
|
122
|
-
const {
|
|
123
|
-
getByText,
|
|
124
|
-
rerender
|
|
125
|
-
} = (0, _index2.render)(_index.default.createElement(Greeting, {
|
|
126
|
-
name: 'Alice'
|
|
127
|
-
}));
|
|
128
|
-
expect(getByText('Hello, Alice!')).toBeDefined();
|
|
129
|
-
rerender(_index.default.createElement(Greeting, {
|
|
130
|
-
name: 'Bob'
|
|
131
|
-
}));
|
|
132
|
-
expect(getByText('Hello, Bob!')).toBeDefined();
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
describe('waitFor', () => {
|
|
136
|
-
test('polls until assertion passes', async () => {
|
|
137
|
-
const {
|
|
138
|
-
getByText
|
|
139
|
-
} = (0, _index2.render)(_index.default.createElement(Greeting, {
|
|
140
|
-
name: 'World'
|
|
141
|
-
}));
|
|
142
|
-
await (0, _index2.waitFor)(() => {
|
|
143
|
-
expect(getByText('Hello, World!')).toBeDefined();
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
test('rejects when assertion never passes', async () => {
|
|
147
|
-
const {
|
|
148
|
-
queryByText
|
|
149
|
-
} = (0, _index2.render)(_index.default.createElement(Greeting, {
|
|
150
|
-
name: 'World'
|
|
151
|
-
}));
|
|
152
|
-
await expect((0, _index2.waitFor)(() => {
|
|
153
|
-
expect(queryByText('MISSING')).not.toBeNull();
|
|
154
|
-
}, {
|
|
155
|
-
timeout: 100,
|
|
156
|
-
interval: 20
|
|
157
|
-
})).rejects.toThrow();
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
describe('data-* attributes', () => {
|
|
161
|
-
test('data-testid is set as an HTML attribute', () => {
|
|
162
|
-
const el = _index.default.createElement('div', {
|
|
163
|
-
'data-testid': 'my-box'
|
|
164
|
-
});
|
|
165
|
-
const {
|
|
166
|
-
container
|
|
167
|
-
} = (0, _index2.render)(el);
|
|
168
|
-
expect(container.querySelector('[data-testid="my-box"]')).not.toBeNull();
|
|
169
|
-
});
|
|
170
|
-
test('getByTestId finds element with data-testid', () => {
|
|
171
|
-
const el = _index.default.createElement('div', {
|
|
172
|
-
'data-testid': 'target'
|
|
173
|
-
}, _index.default.createElement('span', {}, 'inside'));
|
|
174
|
-
const {
|
|
175
|
-
getByTestId
|
|
176
|
-
} = (0, _index2.render)(el);
|
|
177
|
-
expect(getByTestId('target')).toBeDefined();
|
|
178
|
-
});
|
|
179
|
-
test('arbitrary data-* attribute is set as an HTML attribute', () => {
|
|
180
|
-
const el = _index.default.createElement('div', {
|
|
181
|
-
'data-custom': 'value'
|
|
182
|
-
});
|
|
183
|
-
const {
|
|
184
|
-
container
|
|
185
|
-
} = (0, _index2.render)(el);
|
|
186
|
-
expect(container.querySelector('[data-custom="value"]')).not.toBeNull();
|
|
187
|
-
});
|
|
188
|
-
});
|
|
189
|
-
describe('createPortal', () => {
|
|
190
|
-
let portalContainer;
|
|
191
|
-
beforeEach(() => {
|
|
192
|
-
portalContainer = document.createElement('div');
|
|
193
|
-
document.body.appendChild(portalContainer);
|
|
194
|
-
});
|
|
195
|
-
afterEach(() => {
|
|
196
|
-
if (portalContainer.parentNode) {
|
|
197
|
-
portalContainer.parentNode.removeChild(portalContainer);
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
const Portal = () => (0, _index.createPortal)(_index.default.createElement('p', {}, 'Portal content'), portalContainer);
|
|
201
|
-
test('renders content into the portal container, not the render container', () => {
|
|
202
|
-
const {
|
|
203
|
-
queryByText
|
|
204
|
-
} = (0, _index2.render)(_index.default.createElement(Portal, {}));
|
|
205
|
-
expect(portalContainer.textContent).toBe('Portal content');
|
|
206
|
-
expect(queryByText('Portal content')).toBeNull();
|
|
207
|
-
});
|
|
208
|
-
test('within() finds portal content', () => {
|
|
209
|
-
(0, _index2.render)(_index.default.createElement(Portal, {}));
|
|
210
|
-
expect((0, _index2.within)(portalContainer).getByText('Portal content')).toBeDefined();
|
|
211
|
-
});
|
|
212
|
-
test('portal content is removed from the container on unmount', () => {
|
|
213
|
-
const {
|
|
214
|
-
unmount
|
|
215
|
-
} = (0, _index2.render)(_index.default.createElement(Portal, {}));
|
|
216
|
-
expect(portalContainer.textContent).toBe('Portal content');
|
|
217
|
-
unmount();
|
|
218
|
-
expect(portalContainer.textContent).toBe('');
|
|
219
|
-
});
|
|
220
|
-
test('portal content updates when parent state changes', () => {
|
|
221
|
-
class PortalParent extends _index.Component {
|
|
222
|
-
state = {
|
|
223
|
-
label: 'before'
|
|
224
|
-
};
|
|
225
|
-
render() {
|
|
226
|
-
return _index.default.createElement('div', {}, _index.default.createElement('button', {
|
|
227
|
-
onClick: () => this.setState({
|
|
228
|
-
label: 'after'
|
|
229
|
-
})
|
|
230
|
-
}, 'update'), (0, _index.createPortal)(_index.default.createElement('p', {}, this.state.label), portalContainer));
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
const {
|
|
234
|
-
getByRole
|
|
235
|
-
} = (0, _index2.render)(_index.default.createElement(PortalParent, {}));
|
|
236
|
-
expect((0, _index2.within)(portalContainer).getByText('before')).toBeDefined();
|
|
237
|
-
_index2.fireEvent.click(getByRole('button'));
|
|
238
|
-
expect((0, _index2.within)(portalContainer).getByText('after')).toBeDefined();
|
|
239
|
-
});
|
|
240
|
-
});
|
|
241
|
-
describe('act', () => {
|
|
242
|
-
test('flushes state updates synchronously', () => {
|
|
243
|
-
const {
|
|
244
|
-
getByText,
|
|
245
|
-
getByRole
|
|
246
|
-
} = (0, _index2.render)(_index.default.createElement(Counter, {}));
|
|
247
|
-
(0, _index2.act)(() => {
|
|
248
|
-
_index2.fireEvent.click(getByRole('button'));
|
|
249
|
-
});
|
|
250
|
-
expect(getByText('Count: 1')).toBeDefined();
|
|
251
|
-
});
|
|
252
|
-
test('wraps async callbacks', async () => {
|
|
253
|
-
const {
|
|
254
|
-
getByText
|
|
255
|
-
} = (0, _index2.render)(_index.default.createElement(Counter, {}));
|
|
256
|
-
await (0, _index2.act)(async () => {
|
|
257
|
-
await Promise.resolve();
|
|
258
|
-
});
|
|
259
|
-
expect(getByText('Count: 0')).toBeDefined();
|
|
260
|
-
});
|
|
261
|
-
});
|