Skip to content

Commit 2aeb0c4

Browse files
committed
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.
1 parent 9dc31c5 commit 2aeb0c4

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/state.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1461,5 +1461,5 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
14611461
}
14621462

14631463
angular.module('ui.router.state')
1464-
.value('$stateParams', {})
1464+
.factory('$stateParams', function () { return {}; })
14651465
.provider('$state', $StateProvider);

test/stateSpec.js

+15
Original file line numberDiff line numberDiff line change
@@ -1490,3 +1490,18 @@ describe('state queue', function(){
14901490
});
14911491
});
14921492
});
1493+
1494+
describe('$stateParams', function () {
1495+
beforeEach(module('ui.router.state'));
1496+
1497+
it('should start empty', inject(function ($stateParams) {
1498+
expect($stateParams.foo).toBeUndefined();
1499+
}));
1500+
it('should allow setting values on it', inject(function ($stateParams) {
1501+
$stateParams.foo = 'bar';
1502+
expect($stateParams.foo).toBeDefined();
1503+
}));
1504+
it('should be cleared between tests', inject(function ($stateParams) {
1505+
expect($stateParams.foo).toBeUndefined();
1506+
}));
1507+
});

0 commit comments

Comments
 (0)