diff --git a/src/state.js b/src/state.js index 3b44e7d83..905b89e8f 100644 --- a/src/state.js +++ b/src/state.js @@ -133,6 +133,8 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) { } function findState(stateOrName, base) { + if (!stateOrName) return undefined; + var isStr = isString(stateOrName), name = isStr ? stateOrName : stateOrName.name, path = isRelative(name); @@ -1116,7 +1118,7 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) { * @returns {object|array} State configuration object or array of all objects. */ $state.get = function (stateOrName, context) { - if (!isDefined(stateOrName)) { + if (arguments.length === 0) { var list = []; forEach(states, function(state) { list.push(state.self); }); return list; diff --git a/test/stateSpec.js b/test/stateSpec.js index 3829a3699..7dcae9f3f 100644 --- a/test/stateSpec.js +++ b/test/stateSpec.js @@ -726,6 +726,12 @@ describe('state', function () { ]; expect(list.map(function(state) { return state.name; })).toEqual(names); })); + + it("should return undefined on invalid state query", inject(function ($state) { + expect($state.get(null)).toBeNull(); + expect($state.get(false)).toBeNull(); + expect($state.get(undefined)).toBeNull(); + })); }); describe('url handling', function () {