node-browser-compat.js/localStorage/tests/test.js

35 lines
1.0 KiB
JavaScript
Raw Normal View History

2011-07-22 19:21:23 +00:00
(function () {
"use strict";
var assert = require('assert')
, localStorage = require('localStorage')
;
// can't make assuptions about key positioning
localStorage.setItem('a', 1);
assert.strictEqual(localStorage.key(0), 'a');
localStorage.setItem('b', '2');
assert.strictEqual(localStorage.getItem('a'), '1');
assert.strictEqual(localStorage.getItem('b'), '2');
assert.strictEqual(localStorage.length, 2);
assert.strictEqual(localStorage['c'], undefined);
assert.strictEqual(localStorage.getItem('c'), null);
localStorage.setItem('c');
assert.strictEqual(localStorage.getItem('c'), "undefined");
assert.strictEqual(localStorage.length, 3);
localStorage.removeItem('c');
assert.strictEqual(localStorage.getItem('c'), null);
assert.strictEqual(localStorage.length, 2);
localStorage.clear();
assert.strictEqual(localStorage.getItem('a'), null);
assert.strictEqual(localStorage.getItem('b'), null);
assert.strictEqual(localStorage.length, 0);
console.log('All tests passed');
}());