Forked from jouni-kantola/stub-properties-and-methods-sinon.js
Created
February 4, 2016 21:11
-
-
Save dinamic/0c6f24d733d9caceca97 to your computer and use it in GitHub Desktop.
Revisions
-
jouni-kantola created this gist
Feb 2, 2014 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,41 @@ define(['can', 'localCache'], function(can, localCache) { 'use strict'; describe('storeLocal()', function() { var sandbox; beforeEach(function() { // create sandbox environment for mocking about sandbox = sinon.sandbox.create(); }); afterEach(function() { // restore the environment as it was before sandbox.restore(); }); it('should cache in localStorage', function() { // fake localStorage var store = {}, localStorageKey, theOneRing = { my: 'precious' }, expected = JSON.stringify(theOneRing); // stub property for feature detection to use localStorage sandbox.stub(can.use, 'localStorage', true); // stub localStorage's setItem and replace with fake sandbox.stub(window.localStorage, 'setItem', function(key, value) { store[key] = value; localStorageKey = key; }); // call local cache handler localCache.storeLocal(theOneRing); // assert store[localStorageKey].should.equal(expected); }); }); });