1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-07-31 15:24:23 +03:00

spec: Factor MockStorageApi out of webstorage.spec.js

This is useful elsewhere.
This commit is contained in:
Richard van der Hoff
2016-06-02 19:29:25 +01:00
parent e85c1e1231
commit f38f983a46
2 changed files with 55 additions and 30 deletions

View File

@ -5,36 +5,7 @@ var Room = sdk.Room;
var User = sdk.User;
var utils = require("../test-utils");
function MockStorageApi() {
this.data = {};
this.keys = [];
this.length = 0;
}
MockStorageApi.prototype = {
setItem: function(k, v) {
this.data[k] = v;
this._recalc();
},
getItem: function(k) {
return this.data[k] || null;
},
removeItem: function(k) {
delete this.data[k];
this._recalc();
},
key: function(index) {
return this.keys[index];
},
_recalc: function() {
var keys = [];
for (var k in this.data) {
if (!this.data.hasOwnProperty(k)) { continue; }
keys.push(k);
}
this.keys = keys;
this.length = keys.length;
}
};
var MockStorageApi = require("../MockStorageApi");
describe("WebStorageStore", function() {
var store, room;