Skip to content

Commit

Permalink
fix($stateParams): service instance reset between tests
Browse files Browse the repository at this point in the history
A fresh object is created each time $stateParams is initialized, instead of reusing the same instance. This prevents leaking state between unit tests.
  • Loading branch information
pkt-zer0 committed Aug 25, 2015
1 parent 9dc31c5 commit 2aeb0c4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -1461,5 +1461,5 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
}

angular.module('ui.router.state')
.value('$stateParams', {})
.factory('$stateParams', function () { return {}; })
.provider('$state', $StateProvider);
15 changes: 15 additions & 0 deletions test/stateSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}));
});

0 comments on commit 2aeb0c4

Please sign in to comment.