Skip to content

Instantly share code, notes, and snippets.

@timlindvall
Last active August 29, 2015 14:02
Show Gist options
  • Save timlindvall/80e9d72df993802efa8f to your computer and use it in GitHub Desktop.
Save timlindvall/80e9d72df993802efa8f to your computer and use it in GitHub Desktop.
Hopscotch possible unit test for PR #89
//Starting at line 625
it('Should recover gracefully from loss of sessionStorage', function(){
if(!hasSessionStorage){ return; }
hopscotch.startTour({
id: 'hopscotch-test-tour-sessionStorage',
steps: [
{
target: 'shopping-list',
orientation: 'left',
title: 'Shopping List',
content: 'It\'s a shopping list'
},
{
target: 'shopping-list',
orientation: 'left',
title: 'Shopping List',
content: 'It\'s a shopping list'
}
],
skipIfNoElement: false
});
expect(getState('hopscotch.tour.state')).to.be('hopscotch-test-tour-sessionStorage:0');
sinon.stub(sessionStorage, 'setItem', function(){
throw new Error('Session Storage is full!');
});
hopscotch.nextStep();
expect(sessionStorage.setItem.calledOnce).to.be.ok();
expect(getState('hopscotch.tour.state')).to.not.be.ok();
expect(getState('hopscotch.tour.state', true)).to.be('hopscotch-test-tour-sessionStorage:1');
clearState('hopscotch.tour.state');
sessionStorage.setItem.restore();
hopscotch.endTour();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment