This repository has been archived by the owner on Aug 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improves
localStorage
polyfill to store keys as base64
- Loading branch information
1 parent
559f122
commit b89fda3
Showing
3 changed files
with
93 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* eslint-env mocha, browser */ | ||
/* global proclaim */ | ||
|
||
beforeEach(function () { | ||
localStorage.clear(); | ||
localStorage.setItem('hi', 'there'); | ||
}); | ||
|
||
describe('getItem', function () { | ||
it('should get an item', function () { | ||
proclaim.equal(localStorage.getItem('hi'), 'there'); | ||
}); | ||
}); | ||
|
||
describe('setItem', function () { | ||
it('should set an item', function () { | ||
localStorage.setItem('x', 'y'); | ||
proclaim.equal(localStorage.getItem('x'), 'y'); | ||
}); | ||
|
||
it('should set an item with special characters', function () { | ||
var key = 'x [{]}\\|;:\'",<.>/?!@#$%^&*()-_=+\n\t' | ||
localStorage.setItem(key, 'y'); | ||
proclaim.equal(localStorage.getItem(key), 'y'); | ||
}); | ||
|
||
it('should set an item with an empty key', function () { | ||
localStorage.setItem('', 'y'); | ||
proclaim.equal(localStorage.getItem(''), 'y'); | ||
}); | ||
}); | ||
|
||
describe('removeItem', function () { | ||
it('should remove an item', function () { | ||
localStorage.removeItem('hi'); | ||
proclaim.equal(localStorage.getItem('hi'), null); | ||
}); | ||
}); | ||
|
||
describe('key', function () { | ||
it('should get a key', function () { | ||
proclaim.equal(localStorage.key(0), 'hi'); | ||
}); | ||
}); | ||
|
||
describe('clear', function () { | ||
it('should clear all items', function () { | ||
localStorage.clear(); | ||
proclaim.equal(localStorage.getItem('hi'), null); | ||
}); | ||
}); | ||
|
||
describe('length', function () { | ||
it('should get number of items', function () { | ||
proclaim.equal(localStorage.length, 1); | ||
}); | ||
}); |