Skip to content

Commit

Permalink
feat(isStateFilter): Include optional state params.
Browse files Browse the repository at this point in the history
Allows state params to be passed to the `isState` filter for more
accurate matching.
  • Loading branch information
philBrown authored and Phil Brown committed Sep 29, 2015
1 parent 07c046c commit 71d7469
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 71d7469

Please sign in to comment.