diff --git a/test/spec/app.js b/test/spec/app.js index 6567bf9ef6..8a80b435be 100644 --- a/test/spec/app.js +++ b/test/spec/app.js @@ -4,13 +4,8 @@ describe('AppJS', function() { describe('Automatic page refresh', function(){ var clock; beforeEach(function () { - clock = sinon.useFakeTimers(); - sinon.stub(window, "refresher", function(){return true}); - }); - - afterEach(function () { - clock.restore(); - window.refresher.restore(); + clock = sandbox.useFakeTimers(); + sandbox.stub(window, "refresher", function(){return true}); }); it('should not call refresher if idle time is less than 6 hours', function() { diff --git a/test/spec/controllers/authCtrlSpec.js b/test/spec/controllers/authCtrlSpec.js index 598fe0dee4..70e985d76d 100644 --- a/test/spec/controllers/authCtrlSpec.js +++ b/test/spec/controllers/authCtrlSpec.js @@ -10,8 +10,8 @@ describe('Auth Controller', function() { scope = $rootScope.$new(); scope.loginUsername = 'user'; scope.loginPassword = 'pass'; - $window = { location: { href: ""}, alert: sinon.spy() }; - user = { user: {}, authenticate: sinon.spy() }; + $window = { location: { href: ""}, alert: sandbox.spy() }; + user = { user: {}, authenticate: sandbox.spy() }; ctrl = $controller('AuthCtrl', {$scope: scope, $window: $window, User: user}); })); @@ -20,16 +20,16 @@ describe('Auth Controller', function() { $httpBackend.expectPOST('/api/v2/user/auth/local').respond({id: 'abc', token: 'abc'}); scope.auth(); $httpBackend.flush(); - sinon.assert.calledOnce(user.authenticate); - sinon.assert.notCalled($window.alert); + expect(user.authenticate).to.be.calledOnce; + expect($window.alert).to.not.be.called; }); it('should not log in users with incorrect uname / pass', function() { $httpBackend.expectPOST('/api/v2/user/auth/local').respond(404, ''); scope.auth(); $httpBackend.flush(); - sinon.assert.notCalled(user.authenticate); - sinon.assert.calledOnce($window.alert); + expect(user.authenticate).to.not.be.called; + expect($window.alert).to.be.calledOnce; }); }); diff --git a/test/spec/controllers/groupCtrlSpec.js b/test/spec/controllers/groupCtrlSpec.js index a85cb7b810..58f0e197c3 100644 --- a/test/spec/controllers/groupCtrlSpec.js +++ b/test/spec/controllers/groupCtrlSpec.js @@ -30,7 +30,7 @@ describe('Groups Controller', function() { party.type = 'party'; party.members = []; // Ensure we wouldn't pass automatically. - var partyStub = sinon.stub(groups,"party", function() { + var partyStub = sandbox.stub(groups,"party", function() { return party; }); @@ -44,7 +44,7 @@ describe('Groups Controller', function() { guild.type = 'guild'; guild.members.push(user._id); - var myGuilds = sinon.stub(groups,"myGuilds", function() { + var myGuilds = sandbox.stub(groups,"myGuilds", function() { return [guild]; }); @@ -58,7 +58,7 @@ describe('Groups Controller', function() { guild._id = "unique-guild-id"; guild.type = 'guild'; - var myGuilds = sinon.stub(groups,"myGuilds", function() { + var myGuilds = sandbox.stub(groups,"myGuilds", function() { return []; }); @@ -98,7 +98,7 @@ describe("Chat Controller", function() { name: "Princess Bride" }; - var modalSpy = sinon.spy($rootScope, "openModal"); + var modalSpy = sandbox.spy($rootScope, "openModal"); var message = { uuid: 'the-dread-pirate-roberts', user: 'Wesley', @@ -120,7 +120,7 @@ describe("Chat Controller", function() { name: "Princess Bride" }; - var modalSpy = sinon.spy($rootScope, "openModal"); + var modalSpy = sandbox.spy($rootScope, "openModal"); var message = { uuid: 'system', text: 'Wesley attacked the ROUS in the Fire Swamp' @@ -221,7 +221,7 @@ describe("Autocomplete controller", function() { describe("performCompletion", function() { it('triggers autoComplete', function() { - scope.autoComplete = sinon.spy(); + scope.autoComplete = sandbox.spy(); var msg = {user: "boo"}; // scope.autoComplete only cares about user scope.query = {text: "b"}; @@ -247,7 +247,7 @@ describe("Autocomplete controller", function() { describe("chatChanged", function() { it('if a new chat arrives, the new user name is extracted', function() { - var chatChanged = sinon.spy(scope, 'chatChanged'); + var chatChanged = sandbox.spy(scope, 'chatChanged'); scope.$watch('group.chat',scope.chatChanged); // reinstantiate watch so spy works scope.$digest(); // trigger watch @@ -269,11 +269,11 @@ describe("CopyMessageModal controller", function() { user = specHelper.newUser(); user._id = "unique-user-id"; user.ops = { - addTask: sinon.spy() + addTask: sandbox.spy() }; scope = $rootScope.$new(); - scope.$close = sinon.spy(); + scope.$close = sandbox.spy(); $controller = _$controller_; @@ -283,7 +283,7 @@ describe("CopyMessageModal controller", function() { ctrl = $controller('CopyMessageModalCtrl', {$scope: scope, User: {user: user}}); Notification = _Notification_; - Notification.text = sinon.spy(); + Notification.text = sandbox.spy(); }); }); diff --git a/test/spec/controllers/hallCtrlSpec.js b/test/spec/controllers/hallCtrlSpec.js index 15367b5728..5ad0e32c98 100644 --- a/test/spec/controllers/hallCtrlSpec.js +++ b/test/spec/controllers/hallCtrlSpec.js @@ -22,15 +22,12 @@ describe('Hall of Heroes Controller', function() { }); it('populates contributor input with selected hero id', function(){ - var loadHero = sinon.spy(scope, "loadHero"); - var scrollTo = sinon.spy(window, "scrollTo"); + var loadHero = sandbox.spy(scope, "loadHero"); + var scrollTo = sandbox.spy(window, "scrollTo"); scope.populateContributorInput(user._id); expect(scope._heroID).to.eql(user._id); expect(loadHero.callCount).to.eql(1); expect(scrollTo.callCount).to.eql(1); - - scope.loadHero.restore(); - window.scrollTo.restore(); }); }); diff --git a/test/spec/controllers/headerCtrlSpec.js b/test/spec/controllers/headerCtrlSpec.js index 4060519fde..ab37d11205 100644 --- a/test/spec/controllers/headerCtrlSpec.js +++ b/test/spec/controllers/headerCtrlSpec.js @@ -26,13 +26,8 @@ describe('Header Controller', function() { context('inviteOrStartParty', function(){ beforeEach(function(){ - sinon.stub($location, 'path'); - sinon.stub($rootScope, 'openModal'); - }); - - afterEach(function(){ - $location.path.restore(); - $rootScope.openModal.restore(); + sandbox.stub($location, 'path'); + sandbox.stub($rootScope, 'openModal'); }); it('redirects to party page if user does not have a party', function(){ diff --git a/test/spec/controllers/rootCtrlSpec.js b/test/spec/controllers/rootCtrlSpec.js index 15ee64e1cf..648de78d9f 100644 --- a/test/spec/controllers/rootCtrlSpec.js +++ b/test/spec/controllers/rootCtrlSpec.js @@ -24,13 +24,13 @@ describe('Root Controller', function() { $httpBackend = _$httpBackend_; notification = Notification; - sinon.stub(notification, 'text'); - sinon.stub(notification, 'markdown'); + sandbox.stub(notification, 'text'); + sandbox.stub(notification, 'markdown'); user = specHelper.newUser(); User = {user: user}; - User.save = sinon.spy(); - User.sync = sinon.spy(); + User.save = sandbox.spy(); + User.sync = sandbox.spy(); $httpBackend.whenGET(/partials/).respond(); @@ -38,13 +38,6 @@ describe('Root Controller', function() { }); }); - afterEach(function() { - notification.text.reset(); - notification.markdown.reset(); - User.save.reset(); - User.sync.reset(); - }); - describe('contribText', function(){ it('shows contributor level text', function(){ expect(scope.contribText()).to.eql(undefined); diff --git a/test/spec/directives/focus-me.directive.spec.js b/test/spec/directives/focus-me.directive.spec.js index ed016949c3..c91b36a2f3 100644 --- a/test/spec/directives/focus-me.directive.spec.js +++ b/test/spec/directives/focus-me.directive.spec.js @@ -16,7 +16,7 @@ describe('focusMe Directive', function() { it('focuses the element when appended to the DOM', function() { inject(function($timeout) { - var focusSpy = sinon.spy(); + var focusSpy = sandbox.spy(); element.appendTo(document.body); element.on('focus', focusSpy); diff --git a/test/spec/directives/from-now.directive.spec.js b/test/spec/directives/from-now.directive.spec.js index a197f2c331..d39fd4e5ad 100644 --- a/test/spec/directives/from-now.directive.spec.js +++ b/test/spec/directives/from-now.directive.spec.js @@ -11,7 +11,7 @@ describe('fromNow Directive', function() { scope = $rootScope.$new(); scope.message = {}; - sinon.stub(window, 'moment').returns({ + sandbox.stub(window, 'moment').returns({ fromNow: function() { return fromNow }, diff: function() { return diff } }); diff --git a/test/spec/filters/taskOrderingSpec.js b/test/spec/filters/taskOrderingSpec.js index 989a56c7e8..46a9162c49 100644 --- a/test/spec/filters/taskOrderingSpec.js +++ b/test/spec/filters/taskOrderingSpec.js @@ -1,10 +1,11 @@ 'use strict'; describe('Task Ordering Filters', function() { - var filter - , orderBySpy = sinon.spy(); + var filter, orderBySpy; beforeEach(function() { + orderBySpy = sandbox.spy(); + module(function($provide) { $provide.value('orderByFilter', orderBySpy); }); diff --git a/test/spec/services/notificationServicesSpec.js b/test/spec/services/notificationServicesSpec.js index a55cf513cc..277e4431b2 100644 --- a/test/spec/services/notificationServicesSpec.js +++ b/test/spec/services/notificationServicesSpec.js @@ -3,13 +3,11 @@ describe('notificationServices', function() { var notification; - before(function(){ - sinon.stub($, 'pnotify', function(){ + beforeEach(function() { + sandbox.stub($, 'pnotify', function(){ return { click: function(){}} }); - }); - beforeEach(function() { module(function($provide){ $provide.value('User', {}); }); @@ -19,10 +17,6 @@ describe('notificationServices', function() { }); }); - afterEach(function() { - $.pnotify.reset(); - }); - it('notifies coins amount', function() { var SILVER_COIN = ""; var GOLD_COIN = ""; diff --git a/test/spec/services/userServicesSpec.js b/test/spec/services/userServicesSpec.js index 4a361e0b1a..5861f76d8b 100644 --- a/test/spec/services/userServicesSpec.js +++ b/test/spec/services/userServicesSpec.js @@ -7,7 +7,7 @@ describe('userServices', function() { beforeEach(function(){ module(function($provide){ - $window = {href: '', alert: sinon.spy(), location: {search: '', pathname: ''}}; + $window = {href: '', alert: sandbox.spy(), location: {search: '', pathname: ''}}; $provide.value('$window', $window); }); diff --git a/test/spec/specHelper.js b/test/spec/specHelper.js index 80f5858fe8..9ddacdac52 100644 --- a/test/spec/specHelper.js +++ b/test/spec/specHelper.js @@ -1,5 +1,15 @@ beforeEach(module('habitrpg')); +var sandbox; + +beforeEach(function() { + sandbox = sinon.sandbox.create(); +}); + +afterEach(function() { + sandbox.restore(); +}); + specHelper = { newUser: function(){ var buffs = {per:0, int:0, con:0, str:0, stealth: 0, streaks: false};