Skip to content

Commit

Permalink
Added tests for jeromegn#177
Browse files Browse the repository at this point in the history
I'm not able to test the reaction to the storage event as it only fires on the window that's _not_ doing the `setItem` call.
  • Loading branch information
Scott Walton committed Jul 22, 2017
1 parent 6f7e89c commit 44718f2
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions test/localstorage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,30 @@ describe('LocalStorage Model', function() {
});
});

describe('with storage updated from elsewhere', function() {
let newModel;
beforeEach(function() {
newModel = new SavedModel({
id: 10
});
newModel.fetch();
mySavedModel.save({
string: 'Brand new string'
});
});

afterEach(function() {
root.localStorage.clear();
newModel = null;
});

it('will re-fetch new data', function() {
newModel.fetch();

expect(newModel.get('string')).to.eql('Brand new string');
});
});

describe('using ajaxSync: true', function() {
beforeEach(function() {
stub(Bb, 'ajax');
Expand Down Expand Up @@ -399,4 +423,30 @@ describe('LocalStorage Collection', function() {
expect(mySavedCollection.length).to.be(0);
});
});

describe('will fetch from localStorage if updated separately', function() {
let newCollection = null;

beforeEach(function() {
mySavedCollection.create(attributes);
newCollection = new SavedCollection();
newCollection.fetch();
});

afterEach(function() {
newCollection = null;
});

it('fetches the items from the original collection', function() {
expect(newCollection.length).to.equal(1);
});

it('will update future changes', function() {
const newAttributes = clone(attributes);
newAttributes.number = 1338;
mySavedCollection.create(newAttributes);
newCollection.fetch();
expect(newCollection.length).to.equal(2);
});
});
});

0 comments on commit 44718f2

Please sign in to comment.