Skip to content

Commit

Permalink
Merge pull request #2269 from philBrown/patch-1
Browse files Browse the repository at this point in the history
feat: support params in isState filter
  • Loading branch information
nateabele committed Sep 29, 2015
2 parents 07c046c + 71d7469 commit 4da7e59
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/stateFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
*/
$IsStateFilter.$inject = ['$state'];
function $IsStateFilter($state) {
var isFilter = function (state) {
return $state.is(state);
var isFilter = function (state, params) {
return $state.is(state, params);
};
isFilter.$stateful = true;
return isFilter;
Expand Down
15 changes: 14 additions & 1 deletion test/stateFiltersSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ describe('isState filter', function() {
beforeEach(module(function($stateProvider) {
$stateProvider
.state('a', { url: '/' })
.state('a.b', { url: '/b' });
.state('a.b', { url: '/b' })
.state('with-param', { url: '/with/:param' });
}));

it('should return true if the current state exactly matches the input state', inject(function($parse, $state, $q, $rootScope) {
Expand All @@ -17,6 +18,18 @@ describe('isState filter', function() {
$q.flush();
expect($parse('"a" | isState')($rootScope)).toBe(false);
}));

it('should return true if the current state and param matches the input state', inject(function($parse, $state, $q, $rootScope) {
$state.go('with-param', {param: 'a'});
$q.flush();
expect($parse('"with-param" | isState: {param: "a"}')($rootScope)).toBe(true);
}));

it('should return false if the current state and param does not match the input state', inject(function($parse, $state, $q, $rootScope) {
$state.go('with-param', {param: 'b'});
$q.flush();
expect($parse('"with-param" | isState: {param: "a"}')($rootScope)).toBe(false);
}));
});

describe('includedByState filter', function() {
Expand Down

0 comments on commit 4da7e59

Please sign in to comment.