@applicaster/zapp-react-native-bridge 12.0.0-rc.13 → 12.0.0-rc.130

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.
@@ -3,13 +3,9 @@ import { DEFAULT_NAMESPACE } from "../__mocks__/storageMock";
3
3
 
4
4
  const { localStorage } = require("../LocalStorage");
5
5
 
6
- jest.mock("react-native", () => {
7
- const RN = jest.requireActual("react-native");
8
- RN.NativeModules.LocalStorage = NativeLocalStorage;
9
- RN.Platform.OS = "ios";
6
+ const RN = require("react-native");
10
7
 
11
- return RN;
12
- });
8
+ RN.NativeModules.LocalStorage = NativeLocalStorage;
13
9
 
14
10
  const test_key = "test_key";
15
11
  const test_value = "test_value";
@@ -27,494 +23,498 @@ function setUpStorage() {
27
23
  NativeLocalStorage.setItem(obj_key, JSON.stringify(obj_value));
28
24
  }
29
25
 
30
- describe("localStorage - setItem", () => {
31
- beforeEach(async () => {
32
- NativeLocalStorage.__clear();
33
- });
34
-
35
- it("sets an item in storage", async () => {
36
- const key = "test_key";
37
- const value = "test_value";
38
- const result = await localStorage.setItem(key, value);
39
-
40
- expect(result).toBe(true);
41
-
42
- expect(NativeLocalStorage.items.get(DEFAULT_NAMESPACE).get(key)).toEqual(
43
- value
44
- );
45
- });
46
-
47
- it("works as a bound method", async () => {
48
- const key = "test_key";
49
- const value = "test_value";
50
- const setItem = localStorage.setItem;
51
- const result = await setItem(key, value);
52
-
53
- expect(result).toBe(true);
54
-
55
- expect(NativeLocalStorage.items.get(DEFAULT_NAMESPACE).get(key)).toEqual(
56
- value
57
- );
58
- });
59
-
60
- it("stringifies the value if its not a string", async () => {
61
- const key = "test_key";
62
- const value = { objVal: "test_value" };
63
-
64
- const result = await localStorage.setItem(key, value);
65
-
66
- expect(result).toBe(true);
26
+ describe("localStorage", () => {
27
+ describe("setItem", () => {
28
+ beforeEach(async () => {
29
+ NativeLocalStorage.__clear();
30
+ });
67
31
 
68
- expect(NativeLocalStorage.items.get(DEFAULT_NAMESPACE).get(key)).toEqual(
69
- JSON.stringify(value)
70
- );
71
- });
32
+ it("sets an item in storage", async () => {
33
+ const key = "test_key";
34
+ const value = "test_value";
35
+ const result = await localStorage.setItem(key, value);
72
36
 
73
- it("sets a value in a specific namespace", async () => {
74
- const key = "test_key";
75
- const value = "test_value";
76
- const namespace = "test_namespace";
77
- const result = await localStorage.setItem(key, value, namespace);
37
+ expect(result).toBe(true);
78
38
 
79
- expect(result).toBe(true);
39
+ expect(NativeLocalStorage.items.get(DEFAULT_NAMESPACE).get(key)).toEqual(
40
+ value
41
+ );
42
+ });
80
43
 
81
- expect(NativeLocalStorage.items.get(namespace).get(key)).toEqual(value);
82
- });
44
+ it("works as a bound method", async () => {
45
+ const key = "test_key";
46
+ const value = "test_value";
47
+ const setItem = localStorage.setItem;
48
+ const result = await setItem(key, value);
83
49
 
84
- it("throws if key is null", async () => {
85
- const value = "test_value";
50
+ expect(result).toBe(true);
86
51
 
87
- expect(() =>
88
- localStorage.setItem(null, value)
89
- ).rejects.toThrowErrorMatchingSnapshot();
90
- });
52
+ expect(NativeLocalStorage.items.get(DEFAULT_NAMESPACE).get(key)).toEqual(
53
+ value
54
+ );
55
+ });
91
56
 
92
- it("throws if key is undefined", async () => {
93
- const value = "test_value";
57
+ it("stringifies the value if its not a string", async () => {
58
+ const key = "test_key";
59
+ const value = { objVal: "test_value" };
94
60
 
95
- expect(() =>
96
- localStorage.setItem(undefined, value)
97
- ).rejects.toThrowErrorMatchingSnapshot();
98
- });
61
+ const result = await localStorage.setItem(key, value);
99
62
 
100
- it("throws if value is null", async () => {
101
- const key = "test_key";
63
+ expect(result).toBe(true);
102
64
 
103
- expect(() =>
104
- localStorage.setItem(key, null)
105
- ).rejects.toThrowErrorMatchingSnapshot();
106
- });
65
+ expect(NativeLocalStorage.items.get(DEFAULT_NAMESPACE).get(key)).toEqual(
66
+ JSON.stringify(value)
67
+ );
68
+ });
107
69
 
108
- it("throws if value is undefined", async () => {
109
- const key = "test_key";
70
+ it("sets a value in a specific namespace", async () => {
71
+ const key = "test_key";
72
+ const value = "test_value";
73
+ const namespace = "test_namespace";
74
+ const result = await localStorage.setItem(key, value, namespace);
110
75
 
111
- expect(() =>
112
- localStorage.setItem(key, undefined)
113
- ).rejects.toThrowErrorMatchingSnapshot();
114
- });
76
+ expect(result).toBe(true);
115
77
 
116
- it("throws if there is an error in the native module", async () => {
117
- const key = "fail";
118
- const value = "value";
78
+ expect(NativeLocalStorage.items.get(namespace).get(key)).toEqual(value);
79
+ });
119
80
 
120
- expect(() =>
121
- localStorage.setItem(key, value)
122
- ).rejects.toThrowErrorMatchingSnapshot();
123
- });
81
+ it("throws if key is null", async () => {
82
+ const value = "test_value";
124
83
 
125
- describe("listeners", () => {
126
- describe("listening for a specific key and namespace change", () => {
127
- const listener = jest.fn();
128
- const new_value = "new_value";
129
- let removeListener;
84
+ expect(() =>
85
+ localStorage.setItem(null, value)
86
+ ).rejects.toThrowErrorMatchingSnapshot();
87
+ });
130
88
 
131
- beforeEach(() => {
132
- setUpStorage();
133
- listener.mockClear();
89
+ it("throws if key is undefined", async () => {
90
+ const value = "test_value";
134
91
 
135
- removeListener = localStorage.addListener(
136
- { key: namespaced_key, namespace: test_namespace },
137
- listener
138
- );
139
- });
92
+ expect(() =>
93
+ localStorage.setItem(undefined, value)
94
+ ).rejects.toThrowErrorMatchingSnapshot();
95
+ });
140
96
 
141
- it("invokes the listener when this key is changed", async () => {
142
- await localStorage.setItem(namespaced_key, new_value, test_namespace);
97
+ it("throws if value is null", async () => {
98
+ const key = "test_key";
143
99
 
144
- expect(listener).toHaveBeenCalledWith(
145
- expect.objectContaining({
146
- key: namespaced_key,
147
- namespace: test_namespace,
148
- value: new_value,
149
- })
150
- );
151
- });
152
-
153
- it("invokes the listener when the key is changed and is invoked as a bound method", async () => {
154
- const setItem = localStorage.setItem;
155
- await setItem(namespaced_key, new_value, test_namespace);
156
-
157
- expect(listener).toHaveBeenCalledWith(
158
- expect.objectContaining({
159
- key: namespaced_key,
160
- namespace: test_namespace,
161
- value: new_value,
162
- })
163
- );
164
- });
100
+ expect(() =>
101
+ localStorage.setItem(key, null)
102
+ ).rejects.toThrowErrorMatchingSnapshot();
103
+ });
165
104
 
166
- it("is not invoked when another key is changed", async () => {
167
- await localStorage.setItem(test_key, new_value);
105
+ it("throws if value is undefined", async () => {
106
+ const key = "test_key";
168
107
 
169
- expect(listener).not.toHaveBeenCalled();
170
- });
108
+ expect(() =>
109
+ localStorage.setItem(key, undefined)
110
+ ).rejects.toThrowErrorMatchingSnapshot();
111
+ });
171
112
 
172
- it("removes the listener when invoking the remove function", async () => {
173
- removeListener();
113
+ it("throws if there is an error in the native module", async () => {
114
+ const key = "fail";
115
+ const value = "value";
174
116
 
175
- await localStorage.setItem(namespaced_key, new_value, test_namespace);
117
+ expect(() =>
118
+ localStorage.setItem(key, value)
119
+ ).rejects.toThrowErrorMatchingSnapshot();
120
+ });
176
121
 
177
- expect(listener).not.toHaveBeenCalled();
122
+ describe("listeners", () => {
123
+ describe("listening for a specific key and namespace change", () => {
124
+ const listener = jest.fn();
125
+ const new_value = "new_value";
126
+ let removeListener;
127
+
128
+ beforeEach(() => {
129
+ setUpStorage();
130
+ listener.mockClear();
131
+
132
+ removeListener = localStorage.addListener(
133
+ { key: namespaced_key, namespace: test_namespace },
134
+ listener
135
+ );
136
+ });
137
+
138
+ it("invokes the listener when this key is changed", async () => {
139
+ await localStorage.setItem(namespaced_key, new_value, test_namespace);
140
+
141
+ expect(listener).toHaveBeenCalledWith(
142
+ expect.objectContaining({
143
+ key: namespaced_key,
144
+ namespace: test_namespace,
145
+ value: new_value,
146
+ })
147
+ );
148
+ });
149
+
150
+ it("invokes the listener when the key is changed and is invoked as a bound method", async () => {
151
+ const setItem = localStorage.setItem;
152
+ await setItem(namespaced_key, new_value, test_namespace);
153
+
154
+ expect(listener).toHaveBeenCalledWith(
155
+ expect.objectContaining({
156
+ key: namespaced_key,
157
+ namespace: test_namespace,
158
+ value: new_value,
159
+ })
160
+ );
161
+ });
162
+
163
+ it("is not invoked when another key is changed", async () => {
164
+ await localStorage.setItem(test_key, new_value);
165
+
166
+ expect(listener).not.toHaveBeenCalled();
167
+ });
168
+
169
+ it("removes the listener when invoking the remove function", async () => {
170
+ removeListener();
171
+
172
+ await localStorage.setItem(namespaced_key, new_value, test_namespace);
173
+
174
+ expect(listener).not.toHaveBeenCalled();
175
+ });
178
176
  });
179
- });
180
177
 
181
- describe("listening for any key change in a namespace", () => {
182
- const listener = jest.fn();
183
- const new_value = "new_value";
184
- let removeListener;
178
+ describe("listening for any key change in a namespace", () => {
179
+ const listener = jest.fn();
180
+ const new_value = "new_value";
181
+ let removeListener;
185
182
 
186
- beforeEach(() => {
187
- setUpStorage();
188
- listener.mockClear();
183
+ beforeEach(() => {
184
+ setUpStorage();
185
+ listener.mockClear();
189
186
 
190
- removeListener = localStorage.addListener(
191
- { namespace: test_namespace },
192
- listener
193
- );
194
- });
187
+ removeListener = localStorage.addListener(
188
+ { namespace: test_namespace },
189
+ listener
190
+ );
191
+ });
195
192
 
196
- it("is invoked when a key in the namespace is changed", async () => {
197
- await localStorage.setItem(namespaced_key, new_value, test_namespace);
193
+ it("is invoked when a key in the namespace is changed", async () => {
194
+ await localStorage.setItem(namespaced_key, new_value, test_namespace);
198
195
 
199
- expect(listener).toHaveBeenCalledWith(
200
- expect.objectContaining({
201
- key: namespaced_key,
202
- value: new_value,
203
- namespace: test_namespace,
204
- })
205
- );
206
- });
196
+ expect(listener).toHaveBeenCalledWith(
197
+ expect.objectContaining({
198
+ key: namespaced_key,
199
+ value: new_value,
200
+ namespace: test_namespace,
201
+ })
202
+ );
203
+ });
207
204
 
208
- it("is not invoked when a key in a different namespace is changed", async () => {
209
- await localStorage.setItem(test_key, new_value, DEFAULT_NAMESPACE);
205
+ it("is not invoked when a key in a different namespace is changed", async () => {
206
+ await localStorage.setItem(test_key, new_value, DEFAULT_NAMESPACE);
210
207
 
211
- expect(listener).not.toHaveBeenCalled();
212
- });
208
+ expect(listener).not.toHaveBeenCalled();
209
+ });
213
210
 
214
- it("is not invoked after being removed", async () => {
215
- removeListener();
211
+ it("is not invoked after being removed", async () => {
212
+ removeListener();
216
213
 
217
- await localStorage.setItem(namespaced_key, new_value, test_namespace);
214
+ await localStorage.setItem(namespaced_key, new_value, test_namespace);
218
215
 
219
- expect(listener).not.toHaveBeenCalled();
216
+ expect(listener).not.toHaveBeenCalled();
217
+ });
220
218
  });
221
- });
222
219
 
223
- describe("listening for key changes in the default namespace", () => {
224
- const listener = jest.fn();
225
- const new_value = "new_value";
226
- let removeListener;
220
+ describe("listening for key changes in the default namespace", () => {
221
+ const listener = jest.fn();
222
+ const new_value = "new_value";
223
+ let removeListener;
227
224
 
228
- beforeEach(() => {
229
- setUpStorage();
230
- listener.mockClear();
225
+ beforeEach(() => {
226
+ setUpStorage();
227
+ listener.mockClear();
231
228
 
232
- removeListener = localStorage.addListener({}, listener);
233
- });
229
+ removeListener = localStorage.addListener({}, listener);
230
+ });
234
231
 
235
- it("is invoked when a key is changed in the default namespace", async () => {
236
- await localStorage.setItem(test_key, new_value);
232
+ it("is invoked when a key is changed in the default namespace", async () => {
233
+ await localStorage.setItem(test_key, new_value);
237
234
 
238
- expect(listener).toHaveBeenCalledWith(
239
- expect.objectContaining({
240
- key: test_key,
241
- value: new_value,
242
- namespace: DEFAULT_NAMESPACE,
243
- })
244
- );
245
- });
235
+ expect(listener).toHaveBeenCalledWith(
236
+ expect.objectContaining({
237
+ key: test_key,
238
+ value: new_value,
239
+ namespace: DEFAULT_NAMESPACE,
240
+ })
241
+ );
242
+ });
246
243
 
247
- it("is not invoked when a key in a nother namespace is changed", async () => {
248
- await localStorage.setItem(namespaced_key, new_value, test_namespace);
244
+ it("is not invoked when a key in a nother namespace is changed", async () => {
245
+ await localStorage.setItem(namespaced_key, new_value, test_namespace);
249
246
 
250
- expect(listener).not.toHaveBeenCalled();
251
- });
247
+ expect(listener).not.toHaveBeenCalled();
248
+ });
252
249
 
253
- it("is not invoked after having been removed", async () => {
254
- removeListener();
250
+ it("is not invoked after having been removed", async () => {
251
+ removeListener();
255
252
 
256
- await localStorage.setItem(test_key, new_value);
253
+ await localStorage.setItem(test_key, new_value);
257
254
 
258
- expect(listener).not.toHaveBeenCalled();
255
+ expect(listener).not.toHaveBeenCalled();
256
+ });
259
257
  });
260
258
  });
261
259
  });
262
- });
263
260
 
264
- describe("localStorage - getItem", () => {
265
- beforeAll(setUpStorage);
261
+ describe("getItem", () => {
262
+ beforeAll(setUpStorage);
266
263
 
267
- it("retrieves a value from storage", async () => {
268
- const result = await localStorage.getItem(test_key);
269
- expect(result).toBe(test_value);
270
- });
264
+ it("retrieves a value from storage", async () => {
265
+ const result = await localStorage.getItem(test_key);
266
+ expect(result).toBe(test_value);
267
+ });
271
268
 
272
- it("retrieves a value in a namespace", async () => {
273
- const result = await localStorage.getItem(namespaced_key, test_namespace);
274
- expect(result).toBe(namespaced_value);
275
- });
269
+ it("retrieves a value in a namespace", async () => {
270
+ const result = await localStorage.getItem(namespaced_key, test_namespace);
271
+ expect(result).toBe(namespaced_value);
272
+ });
276
273
 
277
- it("retrieves non string values", async () => {
278
- const result = await localStorage.getItem(obj_key);
279
- expect(result).toEqual(obj_value);
280
- });
274
+ it("retrieves non string values", async () => {
275
+ const result = await localStorage.getItem(obj_key);
276
+ expect(result).toEqual(obj_value);
277
+ });
281
278
 
282
- it("works as a bound method", async () => {
283
- const getItem = localStorage.getItem;
284
- const result = await getItem(test_key);
285
- expect(result).toBe(test_value);
286
- });
279
+ it("works as a bound method", async () => {
280
+ const getItem = localStorage.getItem;
281
+ const result = await getItem(test_key);
282
+ expect(result).toBe(test_value);
283
+ });
287
284
 
288
- it("throws if key is null", async () => {
289
- expect(() =>
290
- localStorage.getItem(null)
291
- ).rejects.toThrowErrorMatchingSnapshot();
292
- });
285
+ it("throws if key is null", async () => {
286
+ expect(() =>
287
+ localStorage.getItem(null)
288
+ ).rejects.toThrowErrorMatchingSnapshot();
289
+ });
293
290
 
294
- it("throws if key is undefined", async () => {
295
- expect(() => localStorage.getItem()).rejects.toThrowErrorMatchingSnapshot();
296
- });
291
+ it("throws if key is undefined", async () => {
292
+ expect(() =>
293
+ localStorage.getItem()
294
+ ).rejects.toThrowErrorMatchingSnapshot();
295
+ });
297
296
 
298
- it("throws if there is an error on the native side", async () => {
299
- expect(() =>
300
- localStorage.getItem("fail")
301
- ).rejects.toThrowErrorMatchingSnapshot();
297
+ it("throws if there is an error on the native side", async () => {
298
+ expect(() =>
299
+ localStorage.getItem("fail")
300
+ ).rejects.toThrowErrorMatchingSnapshot();
301
+ });
302
302
  });
303
- });
304
303
 
305
- describe("localStorage - removeItem", () => {
306
- beforeEach(setUpStorage);
304
+ describe("removeItem", () => {
305
+ beforeEach(setUpStorage);
307
306
 
308
- it("removes a value from storage", async () => {
309
- const result = await localStorage.removeItem(test_key);
310
- expect(result).toBe(true);
307
+ it("removes a value from storage", async () => {
308
+ const result = await localStorage.removeItem(test_key);
309
+ expect(result).toBe(true);
311
310
 
312
- expect(
313
- NativeLocalStorage.items.get(DEFAULT_NAMESPACE).get(test_key)
314
- ).toBeUndefined();
315
- });
311
+ expect(
312
+ NativeLocalStorage.items.get(DEFAULT_NAMESPACE).get(test_key)
313
+ ).toBeUndefined();
314
+ });
316
315
 
317
- it("works as a bound method", async () => {
318
- const removeItem = localStorage.removeItem;
319
- const result = await removeItem(test_key);
320
- expect(result).toBe(true);
316
+ it("works as a bound method", async () => {
317
+ const removeItem = localStorage.removeItem;
318
+ const result = await removeItem(test_key);
319
+ expect(result).toBe(true);
321
320
 
322
- expect(
323
- NativeLocalStorage.items.get(DEFAULT_NAMESPACE).get(test_key)
324
- ).toBeUndefined();
325
- });
321
+ expect(
322
+ NativeLocalStorage.items.get(DEFAULT_NAMESPACE).get(test_key)
323
+ ).toBeUndefined();
324
+ });
326
325
 
327
- it("removes a value in a namespace", async () => {
328
- const result = await localStorage.removeItem(
329
- namespaced_key,
330
- test_namespace
331
- );
326
+ it("removes a value in a namespace", async () => {
327
+ const result = await localStorage.removeItem(
328
+ namespaced_key,
329
+ test_namespace
330
+ );
332
331
 
333
- expect(result).toBe(true);
332
+ expect(result).toBe(true);
334
333
 
335
- expect(
336
- NativeLocalStorage.items.get(test_namespace).get(namespaced_key)
337
- ).toBeUndefined();
338
- });
334
+ expect(
335
+ NativeLocalStorage.items.get(test_namespace).get(namespaced_key)
336
+ ).toBeUndefined();
337
+ });
339
338
 
340
- it("throws if key is null", async () => {
341
- expect(() =>
342
- localStorage.removeItem(null)
343
- ).rejects.toThrowErrorMatchingSnapshot();
344
- });
339
+ it("throws if key is null", async () => {
340
+ expect(() =>
341
+ localStorage.removeItem(null)
342
+ ).rejects.toThrowErrorMatchingSnapshot();
343
+ });
345
344
 
346
- it("throws if key is undefined", async () => {
347
- expect(() =>
348
- localStorage.removeItem()
349
- ).rejects.toThrowErrorMatchingSnapshot();
350
- });
345
+ it("throws if key is undefined", async () => {
346
+ expect(() =>
347
+ localStorage.removeItem()
348
+ ).rejects.toThrowErrorMatchingSnapshot();
349
+ });
351
350
 
352
- it("throws if a native error is thrown", async () => {
353
- expect(() =>
354
- localStorage.removeItem("fail")
355
- ).rejects.toThrowErrorMatchingSnapshot();
356
- });
351
+ it("throws if a native error is thrown", async () => {
352
+ expect(() =>
353
+ localStorage.removeItem("fail")
354
+ ).rejects.toThrowErrorMatchingSnapshot();
355
+ });
357
356
 
358
- describe("listeners", () => {
359
- describe("listening for a specific key and namespace change", () => {
360
- const listener = jest.fn();
361
- let removeListener;
357
+ describe("listeners", () => {
358
+ describe("listening for a specific key and namespace change", () => {
359
+ const listener = jest.fn();
360
+ let removeListener;
362
361
 
363
- beforeEach(() => {
364
- setUpStorage();
365
- listener.mockClear();
362
+ beforeEach(() => {
363
+ setUpStorage();
364
+ listener.mockClear();
366
365
 
367
- removeListener = localStorage.addListener(
368
- { key: namespaced_key, namespace: test_namespace },
369
- listener
370
- );
371
- });
366
+ removeListener = localStorage.addListener(
367
+ { key: namespaced_key, namespace: test_namespace },
368
+ listener
369
+ );
370
+ });
372
371
 
373
- it("invokes the listener when this key is changed", async () => {
374
- await localStorage.removeItem(namespaced_key, test_namespace);
372
+ it("invokes the listener when this key is changed", async () => {
373
+ await localStorage.removeItem(namespaced_key, test_namespace);
375
374
 
376
- expect(listener).toHaveBeenCalledWith(
377
- expect.objectContaining({
378
- key: namespaced_key,
379
- namespace: test_namespace,
380
- value: null,
381
- })
382
- );
383
- });
375
+ expect(listener).toHaveBeenCalledWith(
376
+ expect.objectContaining({
377
+ key: namespaced_key,
378
+ namespace: test_namespace,
379
+ value: null,
380
+ })
381
+ );
382
+ });
384
383
 
385
- it("is not invoked when another key is changed", async () => {
386
- await localStorage.removeItem(test_key);
384
+ it("is not invoked when another key is changed", async () => {
385
+ await localStorage.removeItem(test_key);
387
386
 
388
- expect(listener).not.toHaveBeenCalled();
389
- });
387
+ expect(listener).not.toHaveBeenCalled();
388
+ });
390
389
 
391
- it("removes the listener when invoking the remove function", async () => {
392
- removeListener();
390
+ it("removes the listener when invoking the remove function", async () => {
391
+ removeListener();
393
392
 
394
- await localStorage.removeItem(namespaced_key, test_namespace);
393
+ await localStorage.removeItem(namespaced_key, test_namespace);
395
394
 
396
- expect(listener).not.toHaveBeenCalled();
395
+ expect(listener).not.toHaveBeenCalled();
396
+ });
397
397
  });
398
- });
399
398
 
400
- describe("listening for any key change in a namespace", () => {
401
- const listener = jest.fn();
402
- let removeListener;
399
+ describe("listening for any key change in a namespace", () => {
400
+ const listener = jest.fn();
401
+ let removeListener;
403
402
 
404
- beforeEach(() => {
405
- setUpStorage();
406
- listener.mockClear();
403
+ beforeEach(() => {
404
+ setUpStorage();
405
+ listener.mockClear();
407
406
 
408
- removeListener = localStorage.addListener(
409
- { namespace: test_namespace },
410
- listener
411
- );
412
- });
407
+ removeListener = localStorage.addListener(
408
+ { namespace: test_namespace },
409
+ listener
410
+ );
411
+ });
413
412
 
414
- it("is invoked when a key in the namespace is changed", async () => {
415
- await localStorage.removeItem(namespaced_key, test_namespace);
413
+ it("is invoked when a key in the namespace is changed", async () => {
414
+ await localStorage.removeItem(namespaced_key, test_namespace);
416
415
 
417
- expect(listener).toHaveBeenCalledWith(
418
- expect.objectContaining({
419
- key: namespaced_key,
420
- value: null,
421
- namespace: test_namespace,
422
- })
423
- );
424
- });
416
+ expect(listener).toHaveBeenCalledWith(
417
+ expect.objectContaining({
418
+ key: namespaced_key,
419
+ value: null,
420
+ namespace: test_namespace,
421
+ })
422
+ );
423
+ });
425
424
 
426
- it("is not invoked when a key in a different namespace is changed", async () => {
427
- await localStorage.removeItem(test_key, DEFAULT_NAMESPACE);
425
+ it("is not invoked when a key in a different namespace is changed", async () => {
426
+ await localStorage.removeItem(test_key, DEFAULT_NAMESPACE);
428
427
 
429
- expect(listener).not.toHaveBeenCalled();
430
- });
428
+ expect(listener).not.toHaveBeenCalled();
429
+ });
431
430
 
432
- it("is not invoked after being removed", async () => {
433
- removeListener();
431
+ it("is not invoked after being removed", async () => {
432
+ removeListener();
434
433
 
435
- await localStorage.removeItem(namespaced_key, test_namespace);
434
+ await localStorage.removeItem(namespaced_key, test_namespace);
436
435
 
437
- expect(listener).not.toHaveBeenCalled();
436
+ expect(listener).not.toHaveBeenCalled();
437
+ });
438
438
  });
439
- });
440
439
 
441
- describe("listening for key changes in the default namespace", () => {
442
- const listener = jest.fn();
443
- let removeListener;
440
+ describe("listening for key changes in the default namespace", () => {
441
+ const listener = jest.fn();
442
+ let removeListener;
444
443
 
445
- beforeEach(() => {
446
- setUpStorage();
447
- listener.mockClear();
444
+ beforeEach(() => {
445
+ setUpStorage();
446
+ listener.mockClear();
448
447
 
449
- removeListener = localStorage.addListener({}, listener);
450
- });
448
+ removeListener = localStorage.addListener({}, listener);
449
+ });
451
450
 
452
- it("is invoked when a key is changed in the default namespace", async () => {
453
- await localStorage.removeItem(test_key);
451
+ it("is invoked when a key is changed in the default namespace", async () => {
452
+ await localStorage.removeItem(test_key);
454
453
 
455
- expect(listener).toHaveBeenCalledWith(
456
- expect.objectContaining({
457
- key: test_key,
458
- value: null,
459
- namespace: DEFAULT_NAMESPACE,
460
- })
461
- );
462
- });
454
+ expect(listener).toHaveBeenCalledWith(
455
+ expect.objectContaining({
456
+ key: test_key,
457
+ value: null,
458
+ namespace: DEFAULT_NAMESPACE,
459
+ })
460
+ );
461
+ });
463
462
 
464
- it("is not invoked when a key in a nother namespace is changed", async () => {
465
- await localStorage.removeItem(namespaced_key, test_namespace);
463
+ it("is not invoked when a key in a nother namespace is changed", async () => {
464
+ await localStorage.removeItem(namespaced_key, test_namespace);
466
465
 
467
- expect(listener).not.toHaveBeenCalled();
468
- });
466
+ expect(listener).not.toHaveBeenCalled();
467
+ });
469
468
 
470
- it("is not invoked after having been removed", async () => {
471
- removeListener();
469
+ it("is not invoked after having been removed", async () => {
470
+ removeListener();
472
471
 
473
- await localStorage.removeItem(test_key);
472
+ await localStorage.removeItem(test_key);
474
473
 
475
- expect(listener).not.toHaveBeenCalled();
474
+ expect(listener).not.toHaveBeenCalled();
475
+ });
476
476
  });
477
477
  });
478
478
  });
479
- });
480
479
 
481
- describe("localStorage - getAllItems", () => {
482
- beforeAll(setUpStorage);
480
+ describe("getAllItems", () => {
481
+ beforeAll(setUpStorage);
483
482
 
484
- it("retrieves all values", async () => {
485
- const result = await localStorage.getAllItems();
483
+ it("retrieves all values", async () => {
484
+ const result = await localStorage.getAllItems();
486
485
 
487
- expect(result).toEqual(
488
- expect.objectContaining({
489
- [test_key]: test_value,
490
- [obj_key]: obj_value,
491
- })
492
- );
493
- });
486
+ expect(result).toEqual(
487
+ expect.objectContaining({
488
+ [test_key]: test_value,
489
+ [obj_key]: obj_value,
490
+ })
491
+ );
492
+ });
494
493
 
495
- it("works as a bound method", async () => {
496
- const getAllItems = localStorage.getAllItems;
497
- const result = await getAllItems();
494
+ it("works as a bound method", async () => {
495
+ const getAllItems = localStorage.getAllItems;
496
+ const result = await getAllItems();
498
497
 
499
- expect(result).toEqual(
500
- expect.objectContaining({
501
- [test_key]: test_value,
502
- [obj_key]: obj_value,
503
- })
504
- );
505
- });
498
+ expect(result).toEqual(
499
+ expect.objectContaining({
500
+ [test_key]: test_value,
501
+ [obj_key]: obj_value,
502
+ })
503
+ );
504
+ });
506
505
 
507
- it("retrieves all values in a namespace", async () => {
508
- const result = await localStorage.getAllItems(test_namespace);
506
+ it("retrieves all values in a namespace", async () => {
507
+ const result = await localStorage.getAllItems(test_namespace);
509
508
 
510
- expect(result).toEqual(
511
- expect.objectContaining({ [namespaced_key]: namespaced_value })
512
- );
513
- });
509
+ expect(result).toEqual(
510
+ expect.objectContaining({ [namespaced_key]: namespaced_value })
511
+ );
512
+ });
514
513
 
515
- it("throws if an error happen on native side", async () => {
516
- expect(() =>
517
- localStorage.getAllItems("undefined_namespace")
518
- ).rejects.toThrowErrorMatchingSnapshot();
514
+ it("throws if an error happen on native side", async () => {
515
+ expect(() =>
516
+ localStorage.getAllItems("undefined_namespace")
517
+ ).rejects.toThrowErrorMatchingSnapshot();
518
+ });
519
519
  });
520
520
  });