@applicaster/zapp-react-native-bridge 12.0.0-rc.13 → 12.0.0-rc.131
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/OfflineAssets/__tests__/__snapshots__/fileManager.test.ts.snap +2 -2
- package/OfflineAssets/__tests__/fileManager.test.ts +53 -50
- package/OfflineAssets/index.ts +11 -3
- package/PushNotifications/PushTopicManager.ts +6 -7
- package/QuickBrick/__tests__/quickBrickModule.test.ts +45 -49
- package/QuickBrick/__tests__/quickBrickModule_noModule.test.ts +8 -7
- package/ZappStorage/Storage.ts +9 -1
- package/ZappStorage/StorageMultiSelectProvider.ts +45 -22
- package/ZappStorage/__tests__/__snapshots__/localStorage.test.ts.snap +12 -12
- package/ZappStorage/__tests__/__snapshots__/sessionStorage.test.ts.snap +12 -12
- package/ZappStorage/__tests__/localStorage.test.ts +383 -383
- package/ZappStorage/__tests__/localStorageAndroid.test.ts +3 -6
- package/ZappStorage/__tests__/sessionStorage.test.ts +415 -394
- package/package.json +2 -2
|
@@ -3,13 +3,9 @@ import { DEFAULT_NAMESPACE } from "../__mocks__/storageMock";
|
|
|
3
3
|
|
|
4
4
|
const { localStorage } = require("../LocalStorage");
|
|
5
5
|
|
|
6
|
-
|
|
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
|
-
|
|
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
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
69
|
-
|
|
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
|
-
|
|
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
|
-
|
|
39
|
+
expect(NativeLocalStorage.items.get(DEFAULT_NAMESPACE).get(key)).toEqual(
|
|
40
|
+
value
|
|
41
|
+
);
|
|
42
|
+
});
|
|
80
43
|
|
|
81
|
-
|
|
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
|
-
|
|
85
|
-
const value = "test_value";
|
|
50
|
+
expect(result).toBe(true);
|
|
86
51
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
52
|
+
expect(NativeLocalStorage.items.get(DEFAULT_NAMESPACE).get(key)).toEqual(
|
|
53
|
+
value
|
|
54
|
+
);
|
|
55
|
+
});
|
|
91
56
|
|
|
92
|
-
|
|
93
|
-
|
|
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
|
-
|
|
96
|
-
localStorage.setItem(undefined, value)
|
|
97
|
-
).rejects.toThrowErrorMatchingSnapshot();
|
|
98
|
-
});
|
|
61
|
+
const result = await localStorage.setItem(key, value);
|
|
99
62
|
|
|
100
|
-
|
|
101
|
-
const key = "test_key";
|
|
63
|
+
expect(result).toBe(true);
|
|
102
64
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
65
|
+
expect(NativeLocalStorage.items.get(DEFAULT_NAMESPACE).get(key)).toEqual(
|
|
66
|
+
JSON.stringify(value)
|
|
67
|
+
);
|
|
68
|
+
});
|
|
107
69
|
|
|
108
|
-
|
|
109
|
-
|
|
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
|
-
|
|
112
|
-
localStorage.setItem(key, undefined)
|
|
113
|
-
).rejects.toThrowErrorMatchingSnapshot();
|
|
114
|
-
});
|
|
76
|
+
expect(result).toBe(true);
|
|
115
77
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
const value = "value";
|
|
78
|
+
expect(NativeLocalStorage.items.get(namespace).get(key)).toEqual(value);
|
|
79
|
+
});
|
|
119
80
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
).rejects.toThrowErrorMatchingSnapshot();
|
|
123
|
-
});
|
|
81
|
+
it("throws if key is null", async () => {
|
|
82
|
+
const value = "test_value";
|
|
124
83
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
let removeListener;
|
|
84
|
+
expect(() =>
|
|
85
|
+
localStorage.setItem(null, value)
|
|
86
|
+
).rejects.toThrowErrorMatchingSnapshot();
|
|
87
|
+
});
|
|
130
88
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
listener.mockClear();
|
|
89
|
+
it("throws if key is undefined", async () => {
|
|
90
|
+
const value = "test_value";
|
|
134
91
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
});
|
|
92
|
+
expect(() =>
|
|
93
|
+
localStorage.setItem(undefined, value)
|
|
94
|
+
).rejects.toThrowErrorMatchingSnapshot();
|
|
95
|
+
});
|
|
140
96
|
|
|
141
|
-
|
|
142
|
-
|
|
97
|
+
it("throws if value is null", async () => {
|
|
98
|
+
const key = "test_key";
|
|
143
99
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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
|
-
|
|
167
|
-
|
|
105
|
+
it("throws if value is undefined", async () => {
|
|
106
|
+
const key = "test_key";
|
|
168
107
|
|
|
169
|
-
|
|
170
|
-
|
|
108
|
+
expect(() =>
|
|
109
|
+
localStorage.setItem(key, undefined)
|
|
110
|
+
).rejects.toThrowErrorMatchingSnapshot();
|
|
111
|
+
});
|
|
171
112
|
|
|
172
|
-
|
|
173
|
-
|
|
113
|
+
it("throws if there is an error in the native module", async () => {
|
|
114
|
+
const key = "fail";
|
|
115
|
+
const value = "value";
|
|
174
116
|
|
|
175
|
-
|
|
117
|
+
expect(() =>
|
|
118
|
+
localStorage.setItem(key, value)
|
|
119
|
+
).rejects.toThrowErrorMatchingSnapshot();
|
|
120
|
+
});
|
|
176
121
|
|
|
177
|
-
|
|
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
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
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
|
-
|
|
187
|
-
|
|
188
|
-
|
|
183
|
+
beforeEach(() => {
|
|
184
|
+
setUpStorage();
|
|
185
|
+
listener.mockClear();
|
|
189
186
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
187
|
+
removeListener = localStorage.addListener(
|
|
188
|
+
{ namespace: test_namespace },
|
|
189
|
+
listener
|
|
190
|
+
);
|
|
191
|
+
});
|
|
195
192
|
|
|
196
|
-
|
|
197
|
-
|
|
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
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
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
|
-
|
|
209
|
-
|
|
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
|
-
|
|
212
|
-
|
|
208
|
+
expect(listener).not.toHaveBeenCalled();
|
|
209
|
+
});
|
|
213
210
|
|
|
214
|
-
|
|
215
|
-
|
|
211
|
+
it("is not invoked after being removed", async () => {
|
|
212
|
+
removeListener();
|
|
216
213
|
|
|
217
|
-
|
|
214
|
+
await localStorage.setItem(namespaced_key, new_value, test_namespace);
|
|
218
215
|
|
|
219
|
-
|
|
216
|
+
expect(listener).not.toHaveBeenCalled();
|
|
217
|
+
});
|
|
220
218
|
});
|
|
221
|
-
});
|
|
222
219
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
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
|
-
|
|
229
|
-
|
|
230
|
-
|
|
225
|
+
beforeEach(() => {
|
|
226
|
+
setUpStorage();
|
|
227
|
+
listener.mockClear();
|
|
231
228
|
|
|
232
|
-
|
|
233
|
-
|
|
229
|
+
removeListener = localStorage.addListener({}, listener);
|
|
230
|
+
});
|
|
234
231
|
|
|
235
|
-
|
|
236
|
-
|
|
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
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
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
|
-
|
|
248
|
-
|
|
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
|
-
|
|
251
|
-
|
|
247
|
+
expect(listener).not.toHaveBeenCalled();
|
|
248
|
+
});
|
|
252
249
|
|
|
253
|
-
|
|
254
|
-
|
|
250
|
+
it("is not invoked after having been removed", async () => {
|
|
251
|
+
removeListener();
|
|
255
252
|
|
|
256
|
-
|
|
253
|
+
await localStorage.setItem(test_key, new_value);
|
|
257
254
|
|
|
258
|
-
|
|
255
|
+
expect(listener).not.toHaveBeenCalled();
|
|
256
|
+
});
|
|
259
257
|
});
|
|
260
258
|
});
|
|
261
259
|
});
|
|
262
|
-
});
|
|
263
260
|
|
|
264
|
-
describe("
|
|
265
|
-
|
|
261
|
+
describe("getItem", () => {
|
|
262
|
+
beforeAll(setUpStorage);
|
|
266
263
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
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
|
-
|
|
273
|
-
|
|
274
|
-
|
|
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
|
-
|
|
278
|
-
|
|
279
|
-
|
|
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
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
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
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
285
|
+
it("throws if key is null", async () => {
|
|
286
|
+
expect(() =>
|
|
287
|
+
localStorage.getItem(null)
|
|
288
|
+
).rejects.toThrowErrorMatchingSnapshot();
|
|
289
|
+
});
|
|
293
290
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
291
|
+
it("throws if key is undefined", async () => {
|
|
292
|
+
expect(() =>
|
|
293
|
+
localStorage.getItem()
|
|
294
|
+
).rejects.toThrowErrorMatchingSnapshot();
|
|
295
|
+
});
|
|
297
296
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
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("
|
|
306
|
-
|
|
304
|
+
describe("removeItem", () => {
|
|
305
|
+
beforeEach(setUpStorage);
|
|
307
306
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
307
|
+
it("removes a value from storage", async () => {
|
|
308
|
+
const result = await localStorage.removeItem(test_key);
|
|
309
|
+
expect(result).toBe(true);
|
|
311
310
|
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
311
|
+
expect(
|
|
312
|
+
NativeLocalStorage.items.get(DEFAULT_NAMESPACE).get(test_key)
|
|
313
|
+
).toBeUndefined();
|
|
314
|
+
});
|
|
316
315
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
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
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
321
|
+
expect(
|
|
322
|
+
NativeLocalStorage.items.get(DEFAULT_NAMESPACE).get(test_key)
|
|
323
|
+
).toBeUndefined();
|
|
324
|
+
});
|
|
326
325
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
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
|
-
|
|
332
|
+
expect(result).toBe(true);
|
|
334
333
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
334
|
+
expect(
|
|
335
|
+
NativeLocalStorage.items.get(test_namespace).get(namespaced_key)
|
|
336
|
+
).toBeUndefined();
|
|
337
|
+
});
|
|
339
338
|
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
339
|
+
it("throws if key is null", async () => {
|
|
340
|
+
expect(() =>
|
|
341
|
+
localStorage.removeItem(null)
|
|
342
|
+
).rejects.toThrowErrorMatchingSnapshot();
|
|
343
|
+
});
|
|
345
344
|
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
345
|
+
it("throws if key is undefined", async () => {
|
|
346
|
+
expect(() =>
|
|
347
|
+
localStorage.removeItem()
|
|
348
|
+
).rejects.toThrowErrorMatchingSnapshot();
|
|
349
|
+
});
|
|
351
350
|
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
351
|
+
it("throws if a native error is thrown", async () => {
|
|
352
|
+
expect(() =>
|
|
353
|
+
localStorage.removeItem("fail")
|
|
354
|
+
).rejects.toThrowErrorMatchingSnapshot();
|
|
355
|
+
});
|
|
357
356
|
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
357
|
+
describe("listeners", () => {
|
|
358
|
+
describe("listening for a specific key and namespace change", () => {
|
|
359
|
+
const listener = jest.fn();
|
|
360
|
+
let removeListener;
|
|
362
361
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
362
|
+
beforeEach(() => {
|
|
363
|
+
setUpStorage();
|
|
364
|
+
listener.mockClear();
|
|
366
365
|
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
366
|
+
removeListener = localStorage.addListener(
|
|
367
|
+
{ key: namespaced_key, namespace: test_namespace },
|
|
368
|
+
listener
|
|
369
|
+
);
|
|
370
|
+
});
|
|
372
371
|
|
|
373
|
-
|
|
374
|
-
|
|
372
|
+
it("invokes the listener when this key is changed", async () => {
|
|
373
|
+
await localStorage.removeItem(namespaced_key, test_namespace);
|
|
375
374
|
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
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
|
-
|
|
386
|
-
|
|
384
|
+
it("is not invoked when another key is changed", async () => {
|
|
385
|
+
await localStorage.removeItem(test_key);
|
|
387
386
|
|
|
388
|
-
|
|
389
|
-
|
|
387
|
+
expect(listener).not.toHaveBeenCalled();
|
|
388
|
+
});
|
|
390
389
|
|
|
391
|
-
|
|
392
|
-
|
|
390
|
+
it("removes the listener when invoking the remove function", async () => {
|
|
391
|
+
removeListener();
|
|
393
392
|
|
|
394
|
-
|
|
393
|
+
await localStorage.removeItem(namespaced_key, test_namespace);
|
|
395
394
|
|
|
396
|
-
|
|
395
|
+
expect(listener).not.toHaveBeenCalled();
|
|
396
|
+
});
|
|
397
397
|
});
|
|
398
|
-
});
|
|
399
398
|
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
399
|
+
describe("listening for any key change in a namespace", () => {
|
|
400
|
+
const listener = jest.fn();
|
|
401
|
+
let removeListener;
|
|
403
402
|
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
403
|
+
beforeEach(() => {
|
|
404
|
+
setUpStorage();
|
|
405
|
+
listener.mockClear();
|
|
407
406
|
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
407
|
+
removeListener = localStorage.addListener(
|
|
408
|
+
{ namespace: test_namespace },
|
|
409
|
+
listener
|
|
410
|
+
);
|
|
411
|
+
});
|
|
413
412
|
|
|
414
|
-
|
|
415
|
-
|
|
413
|
+
it("is invoked when a key in the namespace is changed", async () => {
|
|
414
|
+
await localStorage.removeItem(namespaced_key, test_namespace);
|
|
416
415
|
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
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
|
-
|
|
427
|
-
|
|
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
|
-
|
|
430
|
-
|
|
428
|
+
expect(listener).not.toHaveBeenCalled();
|
|
429
|
+
});
|
|
431
430
|
|
|
432
|
-
|
|
433
|
-
|
|
431
|
+
it("is not invoked after being removed", async () => {
|
|
432
|
+
removeListener();
|
|
434
433
|
|
|
435
|
-
|
|
434
|
+
await localStorage.removeItem(namespaced_key, test_namespace);
|
|
436
435
|
|
|
437
|
-
|
|
436
|
+
expect(listener).not.toHaveBeenCalled();
|
|
437
|
+
});
|
|
438
438
|
});
|
|
439
|
-
});
|
|
440
439
|
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
440
|
+
describe("listening for key changes in the default namespace", () => {
|
|
441
|
+
const listener = jest.fn();
|
|
442
|
+
let removeListener;
|
|
444
443
|
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
444
|
+
beforeEach(() => {
|
|
445
|
+
setUpStorage();
|
|
446
|
+
listener.mockClear();
|
|
448
447
|
|
|
449
|
-
|
|
450
|
-
|
|
448
|
+
removeListener = localStorage.addListener({}, listener);
|
|
449
|
+
});
|
|
451
450
|
|
|
452
|
-
|
|
453
|
-
|
|
451
|
+
it("is invoked when a key is changed in the default namespace", async () => {
|
|
452
|
+
await localStorage.removeItem(test_key);
|
|
454
453
|
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
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
|
-
|
|
465
|
-
|
|
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
|
-
|
|
468
|
-
|
|
466
|
+
expect(listener).not.toHaveBeenCalled();
|
|
467
|
+
});
|
|
469
468
|
|
|
470
|
-
|
|
471
|
-
|
|
469
|
+
it("is not invoked after having been removed", async () => {
|
|
470
|
+
removeListener();
|
|
472
471
|
|
|
473
|
-
|
|
472
|
+
await localStorage.removeItem(test_key);
|
|
474
473
|
|
|
475
|
-
|
|
474
|
+
expect(listener).not.toHaveBeenCalled();
|
|
475
|
+
});
|
|
476
476
|
});
|
|
477
477
|
});
|
|
478
478
|
});
|
|
479
|
-
});
|
|
480
479
|
|
|
481
|
-
describe("
|
|
482
|
-
|
|
480
|
+
describe("getAllItems", () => {
|
|
481
|
+
beforeAll(setUpStorage);
|
|
483
482
|
|
|
484
|
-
|
|
485
|
-
|
|
483
|
+
it("retrieves all values", async () => {
|
|
484
|
+
const result = await localStorage.getAllItems();
|
|
486
485
|
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
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
|
-
|
|
496
|
-
|
|
497
|
-
|
|
494
|
+
it("works as a bound method", async () => {
|
|
495
|
+
const getAllItems = localStorage.getAllItems;
|
|
496
|
+
const result = await getAllItems();
|
|
498
497
|
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
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
|
-
|
|
508
|
-
|
|
506
|
+
it("retrieves all values in a namespace", async () => {
|
|
507
|
+
const result = await localStorage.getAllItems(test_namespace);
|
|
509
508
|
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
509
|
+
expect(result).toEqual(
|
|
510
|
+
expect.objectContaining({ [namespaced_key]: namespaced_value })
|
|
511
|
+
);
|
|
512
|
+
});
|
|
514
513
|
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
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
|
});
|