mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2024-11-19 18:00:17 +01:00
7619183285
WIP: HD wallets TST REF
35 lines
1.0 KiB
JavaScript
35 lines
1.0 KiB
JavaScript
/* global jest */
|
|
export default class MockStorage {
|
|
constructor(cache = {}) {
|
|
this.storageCache = cache;
|
|
}
|
|
|
|
setItem = jest.fn((key, value) => {
|
|
return new Promise((resolve, reject) => {
|
|
return typeof key !== 'string' || typeof value !== 'string'
|
|
? reject(new Error('key and value must be string'))
|
|
: resolve((this.storageCache[key] = value));
|
|
});
|
|
});
|
|
|
|
getItem = jest.fn(key => {
|
|
return new Promise(resolve => {
|
|
return this.storageCache.hasOwnProperty(key) ? resolve(this.storageCache[key]) : resolve(null);
|
|
});
|
|
});
|
|
|
|
removeItem = jest.fn(key => {
|
|
return new Promise((resolve, reject) => {
|
|
return this.storageCache.hasOwnProperty(key) ? resolve(delete this.storageCache[key]) : reject(new Error('No such key!'));
|
|
});
|
|
});
|
|
|
|
clear = jest.fn(key => {
|
|
return new Promise((resolve, reject) => resolve((this.storageCache = {})));
|
|
});
|
|
|
|
getAllKeys = jest.fn(key => {
|
|
return new Promise((resolve, reject) => resolve(Object.keys(this.storageCache)));
|
|
});
|
|
}
|