diff --git a/src/wizard.js b/src/wizard.js index 0ee5973..8886a8b 100644 --- a/src/wizard.js +++ b/src/wizard.js @@ -64,10 +64,12 @@ angular.module('mgo-angular-wizard').directive('wizard', function() { //checking to make sure currentStep is truthy value if (!step) return; //setting stepTitle equal to current step title or default title - var stepTitle = $scope.selectedStep.wzTitle; - if ($scope.selectedStep && stepTitle !== $scope.currentStep) { - //invoking goTo() with step title as argument - $scope.goTo(stepByTitle($scope.currentStep)); + if($scope.selectedStep) { + var stepTitle = $scope.selectedStep.title || $scope.selectedStep.wzTitle; + if (stepTitle !== $scope.currentStep) { + //invoking goTo() with step title as argument + $scope.goTo(_.findWhere($scope.steps, {title: $scope.currentStep})); + } } }); diff --git a/test/angularWizardSpec.js b/test/angularWizardSpec.js index 728d5e1..e7d8812 100644 --- a/test/angularWizardSpec.js +++ b/test/angularWizardSpec.js @@ -17,10 +17,11 @@ describe( 'AngularWizard', function() { * @param {Scope} scope A scope to bind to * @return {[DOM element]} A DOM element compiled */ - function createGenericView(scope) { + + function createGenericView(scope, element) { scope.referenceCurrentStep = null; - var element = angular.element('' - + ' ' + var element = element || angular.element('' + + ' ' + '

This is the first step

' + '

Here you can use whatever you want. You can use other directives, binding, etc.

' + ' ' @@ -346,4 +347,13 @@ describe( 'AngularWizard', function() { expect(view.isolateScope().steps[index].wzTitle).toEqual(step.title); }); }); + it( "should not throw when currentStep changes and there is no selectedStep", function() { + var scope = $rootScope.$new(); + var element = angular.element(''); + var view = createGenericView(scope, element); + scope.referenceCurrentStep = 'anything'; + expect(function() { + $rootScope.$digest(); + }).not.toThrow(); + }); });