( storage: Storage, getPersister: (store: Store, location: string) => AnyPersister, )
| 177 | }); |
| 178 | |
| 179 | const getMockedStorage = ( |
| 180 | storage: Storage, |
| 181 | getPersister: (store: Store, location: string) => AnyPersister, |
| 182 | ): Persistable => { |
| 183 | const mockStorage = { |
| 184 | getLocation: async (): Promise<string> => 'test' + Math.random(), |
| 185 | getLocationMethod: [ |
| 186 | 'getStorageName', |
| 187 | (location) => location, |
| 188 | ] as GetLocationMethod<string>, |
| 189 | getPersister, |
| 190 | get: async (location: string): Promise<Content | void> => { |
| 191 | try { |
| 192 | return JSON.parse(storage.getItem(location) ?? ''); |
| 193 | } catch {} |
| 194 | }, |
| 195 | set: async ( |
| 196 | location: string, |
| 197 | content: Content | MergeableContent, |
| 198 | ): Promise<void> => |
| 199 | await mockStorage.write(location, JSON.stringify(content)), |
| 200 | write: async (location: string, rawContent: any): Promise<void> => { |
| 201 | storage.setItem(location, rawContent); |
| 202 | window.dispatchEvent( |
| 203 | new StorageEvent('storage', { |
| 204 | storageArea: storage, |
| 205 | key: location, |
| 206 | newValue: rawContent, |
| 207 | }), |
| 208 | ); |
| 209 | window.dispatchEvent( |
| 210 | new StorageEvent('storage', { |
| 211 | storageArea: storage, |
| 212 | key: location + 'another', |
| 213 | }), |
| 214 | ); |
| 215 | }, |
| 216 | del: async (location: string): Promise<void> => |
| 217 | storage.removeItem(location), |
| 218 | testMissing: true, |
| 219 | testAutoLoad: true, |
| 220 | }; |
| 221 | return mockStorage; |
| 222 | }; |
| 223 | |
| 224 | const getMockedDatabase = <Location>( |
| 225 | getLocation: () => Promise<Location>, |
no outgoing calls
no test coverage detected
searching dependent graphs…