From 2aeb0c4b205baf6cfa2ef25bb986bb160dc13bf9 Mon Sep 17 00:00:00 2001 From: pkt-zer0 Date: Mon, 24 Aug 2015 19:11:54 +0200 Subject: [PATCH] fix($stateParams): service instance reset between tests A fresh object is created each time $stateParams is initialized, instead of reusing the same instance. This prevents leaking state between unit tests. --- src/state.js | 2 +- test/stateSpec.js | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/state.js b/src/state.js index 56ee5a055..1df961b94 100644 --- a/src/state.js +++ b/src/state.js @@ -1461,5 +1461,5 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) { } angular.module('ui.router.state') - .value('$stateParams', {}) + .factory('$stateParams', function () { return {}; }) .provider('$state', $StateProvider); diff --git a/test/stateSpec.js b/test/stateSpec.js index e504241c3..9273f95fd 100644 --- a/test/stateSpec.js +++ b/test/stateSpec.js @@ -1490,3 +1490,18 @@ describe('state queue', function(){ }); }); }); + +describe('$stateParams', function () { + beforeEach(module('ui.router.state')); + + it('should start empty', inject(function ($stateParams) { + expect($stateParams.foo).toBeUndefined(); + })); + it('should allow setting values on it', inject(function ($stateParams) { + $stateParams.foo = 'bar'; + expect($stateParams.foo).toBeDefined(); + })); + it('should be cleared between tests', inject(function ($stateParams) { + expect($stateParams.foo).toBeUndefined(); + })); +});