@magic-translate/react 1.15.1 → 1.17.0

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 (35) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/components/Translate.d.ts +5 -5
  3. package/dist/components/Translate.d.ts.map +1 -1
  4. package/dist/components/Translate.js +26 -41
  5. package/dist/components/Translate.js.map +1 -1
  6. package/dist/components/Translate.test.d.ts +1 -1
  7. package/dist/components/Translate.test.js +172 -446
  8. package/dist/components/Translate.test.js.map +1 -1
  9. package/dist/context/MagicTranslateContext.d.ts +31 -24
  10. package/dist/context/MagicTranslateContext.d.ts.map +1 -1
  11. package/dist/context/MagicTranslateContext.js +22 -12
  12. package/dist/context/MagicTranslateContext.js.map +1 -1
  13. package/dist/hooks/use-language-switcher.d.ts +6 -0
  14. package/dist/hooks/use-language-switcher.d.ts.map +1 -0
  15. package/dist/hooks/use-language-switcher.js +7 -0
  16. package/dist/hooks/use-language-switcher.js.map +1 -0
  17. package/dist/hooks/use-magic-translate.d.ts +1 -1
  18. package/dist/hooks/use-magic-translate.d.ts.map +1 -1
  19. package/dist/hooks/use-magic-translate.js +1 -1
  20. package/dist/hooks/use-magic-translate.js.map +1 -1
  21. package/dist/hooks/use-translate.d.ts +3 -3
  22. package/dist/hooks/use-translate.js +11 -28
  23. package/dist/hooks/use-translate.js.map +1 -1
  24. package/dist/hooks/use-translate.test.d.ts +1 -1
  25. package/dist/hooks/use-translate.test.js +65 -117
  26. package/dist/hooks/use-translate.test.js.map +1 -1
  27. package/dist/index.d.ts +5 -4
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.es.js +2 -2
  30. package/dist/index.es.js.map +1 -1
  31. package/dist/index.js +1 -0
  32. package/dist/index.js.map +1 -1
  33. package/dist/index.min.js +3 -2
  34. package/dist/index.min.js.map +1 -1
  35. package/package.json +50 -53
@@ -1,478 +1,204 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __generator = (this && this.__generator) || function (thisArg, body) {
11
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
- function verb(n) { return function (v) { return step([n, v]); }; }
14
- function step(op) {
15
- if (f) throw new TypeError("Generator is already executing.");
16
- while (_) try {
17
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
- if (y = 0, t) op = [op[0] & 2, t.value];
19
- switch (op[0]) {
20
- case 0: case 1: t = op; break;
21
- case 4: _.label++; return { value: op[1], done: false };
22
- case 5: _.label++; y = op[1]; op = [0]; continue;
23
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
- default:
25
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
- if (t[2]) _.ops.pop();
30
- _.trys.pop(); continue;
31
- }
32
- op = body.call(thisArg, _);
33
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
- }
36
- };
37
1
  import { act, render, waitFor } from '@testing-library/react';
38
2
  import { MagicTranslateProvider } from '../context/MagicTranslateContext';
39
3
  import React, { useState } from 'react';
40
4
  import { T } from './Translate';
41
5
  import { Language } from '@magic-translate/core';
42
- var tick = function () { return new Promise(function (resolve) { return setTimeout(resolve); }); };
43
- var ExampleComponent = function () { return React.createElement(React.Fragment, null, "Some component"); };
6
+ const tick = () => new Promise((resolve) => setTimeout(resolve));
7
+ const ExampleComponent = () => React.createElement(React.Fragment, null, "Some component");
44
8
  ExampleComponent.displayName = 'ExampleComponent';
45
- describe('Translate', function () {
46
- var lang = Language.DE;
47
- var sourceLang = Language.EN;
48
- var mockFn = jest.fn();
49
- var loader = function () { return function (content) {
9
+ describe('Translate', () => {
10
+ const lang = Language.DE;
11
+ const mockFn = jest.fn();
12
+ const loader = () => (content) => {
50
13
  // for some reason when using the mock directly the mock is not called. This is a workaround
51
14
  mockFn(content);
52
- return Promise.resolve(content.map(function (item) { return "Translated: ".concat(item.text); }));
53
- }; };
54
- var Wrapper = function (_a) {
55
- var children = _a.children;
56
- return (React.createElement(MagicTranslateProvider, { _loaderFactory: loader, language: lang, apiKey: "test-api-key" }, children));
15
+ return Promise.resolve(content.map((item) => `Translated: ${item.text}`));
57
16
  };
58
- afterEach(function () {
17
+ const Wrapper = ({ children, }) => (React.createElement(MagicTranslateProvider, { _loaderFactory: loader, language: lang, apiKey: "test-api-key" }, children));
18
+ afterEach(() => {
59
19
  mockFn.mockReset();
60
20
  });
61
- it('should call the loader with the content', function () { return __awaiter(void 0, void 0, void 0, function () {
62
- return __generator(this, function (_a) {
63
- switch (_a.label) {
64
- case 0:
65
- // given
66
- render(React.createElement(Wrapper, null,
67
- React.createElement("button", null,
68
- React.createElement(T, null, "test"))));
69
- return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
70
- return __generator(this, function (_a) {
71
- switch (_a.label) {
72
- case 0: return [4 /*yield*/, tick()];
73
- case 1:
74
- _a.sent();
75
- return [2 /*return*/];
76
- }
77
- });
78
- }); })];
79
- case 1:
80
- _a.sent();
81
- // then
82
- expect(mockFn).toHaveBeenCalledWith([{ text: 'test' }]);
83
- return [2 /*return*/];
84
- }
21
+ it('should call the loader with the content', async () => {
22
+ // given
23
+ render(React.createElement(Wrapper, null,
24
+ React.createElement("button", null,
25
+ React.createElement(T, null, "test"))));
26
+ await act(async () => {
27
+ await tick();
85
28
  });
86
- }); });
87
- it('should call the loader with the correct options', function () { return __awaiter(void 0, void 0, void 0, function () {
88
- return __generator(this, function (_a) {
89
- switch (_a.label) {
90
- case 0:
91
- // given
92
- render(React.createElement(Wrapper, null,
93
- React.createElement("button", null,
94
- React.createElement(T, { lang: Language.ZH }, "test"))));
95
- return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
96
- return __generator(this, function (_a) {
97
- switch (_a.label) {
98
- case 0: return [4 /*yield*/, tick()];
99
- case 1:
100
- _a.sent();
101
- return [2 /*return*/];
102
- }
103
- });
104
- }); })];
105
- case 1:
106
- _a.sent();
107
- // then
108
- expect(mockFn).toHaveBeenCalledWith([{ text: 'test', lang: Language.ZH }]);
109
- return [2 /*return*/];
110
- }
29
+ // then
30
+ expect(mockFn).toHaveBeenCalledWith([{ text: 'test' }]);
31
+ });
32
+ it('should call the loader with the correct options', async () => {
33
+ // given
34
+ render(React.createElement(Wrapper, null,
35
+ React.createElement("button", null,
36
+ React.createElement(T, { lang: Language.ZH }, "test"))));
37
+ await act(async () => {
38
+ await tick();
111
39
  });
112
- }); });
113
- it('should call the loader with multiple contents', function () { return __awaiter(void 0, void 0, void 0, function () {
114
- return __generator(this, function (_a) {
115
- switch (_a.label) {
116
- case 0:
117
- // given
118
- render(React.createElement(Wrapper, null,
119
- React.createElement("button", null,
120
- React.createElement(T, null, "test1"),
121
- React.createElement(T, null, "test2"))));
122
- return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
123
- return __generator(this, function (_a) {
124
- switch (_a.label) {
125
- case 0: return [4 /*yield*/, tick()];
126
- case 1:
127
- _a.sent();
128
- return [2 /*return*/];
129
- }
130
- });
131
- }); })];
132
- case 1:
133
- _a.sent();
134
- // then
135
- expect(mockFn).toHaveBeenCalledWith([{ text: 'test1' }, { text: 'test2' }]);
136
- return [2 /*return*/];
137
- }
40
+ // then
41
+ expect(mockFn).toHaveBeenCalledWith([{ text: 'test', lang: Language.ZH }]);
42
+ });
43
+ it('should call the loader with multiple contents', async () => {
44
+ // given
45
+ render(React.createElement(Wrapper, null,
46
+ React.createElement("button", null,
47
+ React.createElement(T, null, "test1"),
48
+ React.createElement(T, null, "test2"))));
49
+ await act(async () => {
50
+ await tick();
138
51
  });
139
- }); });
140
- it('should call the loader with the html inside the translate component', function () { return __awaiter(void 0, void 0, void 0, function () {
141
- return __generator(this, function (_a) {
142
- switch (_a.label) {
143
- case 0:
144
- // given
145
- render(React.createElement(Wrapper, null,
146
- React.createElement(T, null,
147
- React.createElement("button", null, "test"))));
148
- return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
149
- return __generator(this, function (_a) {
150
- switch (_a.label) {
151
- case 0: return [4 /*yield*/, tick()];
152
- case 1:
153
- _a.sent();
154
- return [2 /*return*/];
155
- }
156
- });
157
- }); })];
158
- case 1:
159
- _a.sent();
160
- // then
161
- expect(mockFn).toHaveBeenCalledWith([{ text: '<button>test</button>' }]);
162
- return [2 /*return*/];
163
- }
52
+ // then
53
+ expect(mockFn).toHaveBeenCalledWith([{ text: 'test1' }, { text: 'test2' }]);
54
+ });
55
+ it('should call the loader with the html inside the translate component', async () => {
56
+ // given
57
+ render(React.createElement(Wrapper, null,
58
+ React.createElement(T, null,
59
+ React.createElement("button", null, "test"))));
60
+ await act(async () => {
61
+ await tick();
164
62
  });
165
- }); });
166
- it('should call the loader with multiple html elements the translate component', function () { return __awaiter(void 0, void 0, void 0, function () {
167
- return __generator(this, function (_a) {
168
- switch (_a.label) {
169
- case 0:
170
- // given
171
- render(React.createElement(Wrapper, null,
172
- React.createElement(T, null,
173
- React.createElement("span", null, "span1"),
174
- React.createElement("span", null, "span2"))));
175
- return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
176
- return __generator(this, function (_a) {
177
- switch (_a.label) {
178
- case 0: return [4 /*yield*/, tick()];
179
- case 1:
180
- _a.sent();
181
- return [2 /*return*/];
182
- }
183
- });
184
- }); })];
185
- case 1:
186
- _a.sent();
187
- // then
188
- expect(mockFn).toHaveBeenCalledWith([
189
- { text: '<span>span1</span><span>span2</span>' },
190
- ]);
191
- return [2 /*return*/];
192
- }
63
+ // then
64
+ expect(mockFn).toHaveBeenCalledWith([{ text: '<button>test</button>' }]);
65
+ });
66
+ it('should call the loader with multiple html elements the translate component', async () => {
67
+ // given
68
+ render(React.createElement(Wrapper, null,
69
+ React.createElement(T, null,
70
+ React.createElement("span", null, "span1"),
71
+ React.createElement("span", null, "span2"))));
72
+ await act(async () => {
73
+ await tick();
193
74
  });
194
- }); });
195
- it('should not call the loader if the only child is a number', function () { return __awaiter(void 0, void 0, void 0, function () {
196
- return __generator(this, function (_a) {
197
- switch (_a.label) {
198
- case 0:
199
- // given
200
- render(React.createElement(Wrapper, null,
201
- React.createElement(T, null, 1)));
202
- return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
203
- return __generator(this, function (_a) {
204
- switch (_a.label) {
205
- case 0: return [4 /*yield*/, tick()];
206
- case 1:
207
- _a.sent();
208
- return [2 /*return*/];
209
- }
210
- });
211
- }); })];
212
- case 1:
213
- _a.sent();
214
- // then
215
- expect(mockFn).not.toHaveBeenCalled();
216
- return [2 /*return*/];
217
- }
75
+ // then
76
+ expect(mockFn).toHaveBeenCalledWith([
77
+ { text: '<span>span1</span><span>span2</span>' },
78
+ ]);
79
+ });
80
+ it('should not call the loader if the only child is a number', async () => {
81
+ // given
82
+ render(React.createElement(Wrapper, null,
83
+ React.createElement(T, null, 1)));
84
+ await act(async () => {
85
+ await tick();
218
86
  });
219
- }); });
220
- it('should not call the loader if the only child is a boolean', function () { return __awaiter(void 0, void 0, void 0, function () {
221
- return __generator(this, function (_a) {
222
- switch (_a.label) {
223
- case 0:
224
- // given
225
- render(React.createElement(Wrapper, null,
226
- React.createElement(T, null, true)));
227
- return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
228
- return __generator(this, function (_a) {
229
- switch (_a.label) {
230
- case 0: return [4 /*yield*/, tick()];
231
- case 1:
232
- _a.sent();
233
- return [2 /*return*/];
234
- }
235
- });
236
- }); })];
237
- case 1:
238
- _a.sent();
239
- // then
240
- expect(mockFn).not.toHaveBeenCalled();
241
- return [2 /*return*/];
242
- }
87
+ // then
88
+ expect(mockFn).not.toHaveBeenCalled();
89
+ });
90
+ it('should not call the loader if the only child is a boolean', async () => {
91
+ // given
92
+ render(React.createElement(Wrapper, null,
93
+ React.createElement(T, null, true)));
94
+ await act(async () => {
95
+ await tick();
243
96
  });
244
- }); });
245
- it('should not call the loader if the translate component has no children at all', function () { return __awaiter(void 0, void 0, void 0, function () {
246
- return __generator(this, function (_a) {
247
- switch (_a.label) {
248
- case 0:
249
- // given
250
- render(React.createElement(Wrapper, null,
251
- React.createElement(T, null)));
252
- return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
253
- return __generator(this, function (_a) {
254
- switch (_a.label) {
255
- case 0: return [4 /*yield*/, tick()];
256
- case 1:
257
- _a.sent();
258
- return [2 /*return*/];
259
- }
260
- });
261
- }); })];
262
- case 1:
263
- _a.sent();
264
- // then
265
- expect(mockFn).not.toHaveBeenCalled();
266
- return [2 /*return*/];
267
- }
97
+ // then
98
+ expect(mockFn).not.toHaveBeenCalled();
99
+ });
100
+ it('should not call the loader if the translate component has no children at all', async () => {
101
+ // given
102
+ render(React.createElement(Wrapper, null,
103
+ React.createElement(T, null)));
104
+ await act(async () => {
105
+ await tick();
268
106
  });
269
- }); });
270
- it('should throw an error if there is a react component inside the translation component', function () { return __awaiter(void 0, void 0, void 0, function () {
271
- return __generator(this, function (_a) {
272
- switch (_a.label) {
273
- case 0:
274
- // given
275
- try {
276
- render(React.createElement(Wrapper, null,
277
- React.createElement(T, null,
278
- React.createElement(ExampleComponent, null))));
279
- }
280
- catch (err) {
281
- expect(err.message).toContain('ExampleComponent');
282
- }
283
- return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
284
- return __generator(this, function (_a) {
285
- switch (_a.label) {
286
- case 0: return [4 /*yield*/, tick()];
287
- case 1:
288
- _a.sent();
289
- return [2 /*return*/];
290
- }
291
- });
292
- }); })];
293
- case 1:
294
- _a.sent();
295
- // then
296
- expect(mockFn).not.toHaveBeenCalled();
297
- return [2 /*return*/];
298
- }
107
+ // then
108
+ expect(mockFn).not.toHaveBeenCalled();
109
+ });
110
+ it('should throw an error if there is a react component inside the translation component', async () => {
111
+ // given
112
+ try {
113
+ render(React.createElement(Wrapper, null,
114
+ React.createElement(T, null,
115
+ React.createElement(ExampleComponent, null))));
116
+ }
117
+ catch (err) {
118
+ expect(err.message).toContain('ExampleComponent');
119
+ }
120
+ await act(async () => {
121
+ await tick();
299
122
  });
300
- }); });
301
- it('should throw an error if any child of the translate component is a react component', function () { return __awaiter(void 0, void 0, void 0, function () {
302
- return __generator(this, function (_a) {
303
- switch (_a.label) {
304
- case 0:
305
- // given
306
- try {
307
- render(React.createElement(Wrapper, null,
308
- React.createElement(T, null,
309
- "test",
310
- React.createElement(ExampleComponent, null))));
311
- }
312
- catch (err) {
313
- expect(err.message).toContain('ExampleComponent');
314
- }
315
- return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
316
- return __generator(this, function (_a) {
317
- switch (_a.label) {
318
- case 0: return [4 /*yield*/, tick()];
319
- case 1:
320
- _a.sent();
321
- return [2 /*return*/];
322
- }
323
- });
324
- }); })];
325
- case 1:
326
- _a.sent();
327
- // then
328
- expect(mockFn).not.toHaveBeenCalled();
329
- return [2 /*return*/];
330
- }
123
+ // then
124
+ expect(mockFn).not.toHaveBeenCalled();
125
+ });
126
+ it('should throw an error if any child of the translate component is a react component', async () => {
127
+ // given
128
+ try {
129
+ render(React.createElement(Wrapper, null,
130
+ React.createElement(T, null,
131
+ "test",
132
+ React.createElement(ExampleComponent, null))));
133
+ }
134
+ catch (err) {
135
+ expect(err.message).toContain('ExampleComponent');
136
+ }
137
+ await act(async () => {
138
+ await tick();
331
139
  });
332
- }); });
333
- it('should replace the content with the loaded content', function () { return __awaiter(void 0, void 0, void 0, function () {
334
- var getByRole;
335
- return __generator(this, function (_a) {
336
- switch (_a.label) {
337
- case 0:
338
- getByRole = render(React.createElement(Wrapper, null,
339
- React.createElement("button", null,
340
- React.createElement(T, null, "test")))).getByRole;
341
- return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
342
- return __generator(this, function (_a) {
343
- switch (_a.label) {
344
- case 0: return [4 /*yield*/, tick()];
345
- case 1:
346
- _a.sent();
347
- return [2 /*return*/];
348
- }
349
- });
350
- }); })];
351
- case 1:
352
- _a.sent();
353
- // then
354
- return [4 /*yield*/, waitFor(function () {
355
- return expect(getByRole('button').textContent).toContain('Translated: test');
356
- })];
357
- case 2:
358
- // then
359
- _a.sent();
360
- return [2 /*return*/];
361
- }
140
+ // then
141
+ expect(mockFn).not.toHaveBeenCalled();
142
+ });
143
+ it('should replace the content with the loaded content', async () => {
144
+ // given
145
+ const { getByRole } = render(React.createElement(Wrapper, null,
146
+ React.createElement("button", null,
147
+ React.createElement(T, null, "test"))));
148
+ await act(async () => {
149
+ await tick();
362
150
  });
363
- }); });
364
- it('should replace the content the translated HTML', function () { return __awaiter(void 0, void 0, void 0, function () {
365
- var getByTestId;
366
- return __generator(this, function (_a) {
367
- switch (_a.label) {
368
- case 0:
369
- getByTestId = render(React.createElement(Wrapper, null,
370
- React.createElement("div", { "data-testid": "wrapper" },
371
- React.createElement(T, null,
372
- React.createElement("span", null, "test"))))).getByTestId;
373
- return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
374
- return __generator(this, function (_a) {
375
- switch (_a.label) {
376
- case 0: return [4 /*yield*/, tick()];
377
- case 1:
378
- _a.sent();
379
- return [2 /*return*/];
380
- }
381
- });
382
- }); })];
383
- case 1:
384
- _a.sent();
385
- // then
386
- return [4 /*yield*/, waitFor(function () {
387
- return expect(getByTestId('wrapper').innerHTML).toContain('Translated: <span>test</span>');
388
- })];
389
- case 2:
390
- // then
391
- _a.sent();
392
- return [2 /*return*/];
393
- }
151
+ // then
152
+ await waitFor(() => expect(getByRole('button').textContent).toContain('Translated: test'));
153
+ });
154
+ it('should replace the content the translated HTML', async () => {
155
+ // given
156
+ const { getByTestId } = render(React.createElement(Wrapper, null,
157
+ React.createElement("div", { "data-testid": "wrapper" },
158
+ React.createElement(T, null,
159
+ React.createElement("span", null, "test")))));
160
+ await act(async () => {
161
+ await tick();
394
162
  });
395
- }); });
396
- describe('interactivity', function () {
397
- var InteractiveComonent = function () {
398
- var _a = useState('red'), color = _a[0], setColor = _a[1];
163
+ // then
164
+ await waitFor(() => expect(getByTestId('wrapper').innerHTML).toContain('Translated: <span>test</span>'));
165
+ });
166
+ describe('interactivity', () => {
167
+ const InteractiveComonent = () => {
168
+ const [color, setColor] = useState('red');
399
169
  return (React.createElement(React.Fragment, null,
400
- React.createElement("button", { onClick: function () { return setColor('blue'); } }, "blue"),
170
+ React.createElement("button", { onClick: () => setColor('blue') }, "blue"),
401
171
  React.createElement("div", { "data-testid": "wrapper" },
402
172
  React.createElement(T, null,
403
- React.createElement("div", { style: { color: color } }, "test")))));
173
+ React.createElement("div", { style: { color } }, "test")))));
404
174
  };
405
- it('should update the HTML inside the translate component', function () { return __awaiter(void 0, void 0, void 0, function () {
406
- var _a, getByRole, getByTestId;
407
- return __generator(this, function (_b) {
408
- switch (_b.label) {
409
- case 0:
410
- _a = render(React.createElement(Wrapper, null,
411
- React.createElement(InteractiveComonent, null))), getByRole = _a.getByRole, getByTestId = _a.getByTestId;
412
- return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
413
- return __generator(this, function (_a) {
414
- switch (_a.label) {
415
- case 0: return [4 /*yield*/, tick()];
416
- case 1:
417
- _a.sent();
418
- // when
419
- getByRole('button').click();
420
- return [2 /*return*/];
421
- }
422
- });
423
- }); })];
424
- case 1:
425
- _b.sent();
426
- // then
427
- return [4 /*yield*/, waitFor(function () {
428
- return expect(getByTestId('wrapper').innerHTML).toContain("Translated: <div style=\"color: blue;\">test</div>");
429
- })];
430
- case 2:
431
- // then
432
- _b.sent();
433
- return [2 /*return*/];
434
- }
175
+ it('should update the HTML inside the translate component', async () => {
176
+ // given
177
+ const { getByRole, getByTestId } = render(React.createElement(Wrapper, null,
178
+ React.createElement(InteractiveComonent, null)));
179
+ await act(async () => {
180
+ await tick();
181
+ // when
182
+ getByRole('button').click();
183
+ });
184
+ // then
185
+ await waitFor(() => expect(getByTestId('wrapper').innerHTML).toContain(`Translated: <div style="color: blue;">test</div>`));
186
+ });
187
+ it('should call the loader again when children updated', async () => {
188
+ // given
189
+ const { getByRole } = render(React.createElement(Wrapper, null,
190
+ React.createElement(InteractiveComonent, null)));
191
+ await act(async () => {
192
+ await tick();
435
193
  });
436
- }); });
437
- it('should call the loader again when children updated', function () { return __awaiter(void 0, void 0, void 0, function () {
438
- var getByRole;
439
- return __generator(this, function (_a) {
440
- switch (_a.label) {
441
- case 0:
442
- getByRole = render(React.createElement(Wrapper, null,
443
- React.createElement(InteractiveComonent, null))).getByRole;
444
- return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
445
- return __generator(this, function (_a) {
446
- switch (_a.label) {
447
- case 0: return [4 /*yield*/, tick()];
448
- case 1:
449
- _a.sent();
450
- return [2 /*return*/];
451
- }
452
- });
453
- }); })];
454
- case 1:
455
- _a.sent();
456
- // when
457
- getByRole('button').click();
458
- return [4 /*yield*/, act(function () { return __awaiter(void 0, void 0, void 0, function () {
459
- return __generator(this, function (_a) {
460
- switch (_a.label) {
461
- case 0: return [4 /*yield*/, tick()];
462
- case 1:
463
- _a.sent();
464
- return [2 /*return*/];
465
- }
466
- });
467
- }); })];
468
- case 2:
469
- _a.sent();
470
- // then
471
- expect(mockFn).toHaveBeenCalledTimes(2);
472
- return [2 /*return*/];
473
- }
194
+ // when
195
+ getByRole('button').click();
196
+ await act(async () => {
197
+ await tick();
474
198
  });
475
- }); });
199
+ // then
200
+ expect(mockFn).toHaveBeenCalledTimes(2);
201
+ });
476
202
  });
477
203
  });
478
204
  //# sourceMappingURL=Translate.test.js.map