json-storage.js/test/test.js

32 lines
757 B
JavaScript
Raw Normal View History

2011-09-05 21:48:34 +00:00
(function () {
"use strict";
var localStorage = require('localStorage')
, JsonStorage = require('../lib/').JsonStorage
, db = JsonStorage.create(localStorage)
2011-09-05 21:48:34 +00:00
, assert = require('assert')
;
assert.equal(null, db.get('x'));
2012-03-02 18:35:53 +00:00
assert.deepEqual([], db.keys(), 'found keys in empty db: ' + JSON.stringify(db.keys()));
2011-09-05 21:48:34 +00:00
db.clear();
assert.equal(null, db.get('x'));
db.set('a', 'b');
assert.deepEqual(['a'], db.keys());
assert.equal('b', db.get('a'));
db.remove('a');
assert.deepEqual([], db.keys());
db.set('a', 'b');
db.clear();
assert.deepEqual([], db.keys());
2012-03-02 18:35:53 +00:00
db.set('a', 'b');
assert.deepEqual(['a'], db.keys());
assert.deepEqual({ 'a': 'b' }, db.toJSON());
2011-09-05 21:48:34 +00:00
console.log("Done! All tests pass.");
}());