在jasmine中为不同的值重复测试用例

时间:2016-01-20 09:04:11

标签: angularjs unit-testing loops jasmine bdd

我在控制器中有以下代码

$scope.changeForm = function(num,fromLink){
        $scope.userEmail_sign = '';
        $scope.pass_sign = '';
        $scope.normalizeMessages(fromLink);
        $scope.userEmail_reg = '';
        $scope.npi = '';
        $scope.password_reg = '';
        $scope.confirmPassword_reg = '';
        $scope.userEmail_forgotPwd = '';
        $scope.formCode = num;
        if(num == 2){
            $location.path("/auth/register");
        }else if (num == 3){
            $location.path("/auth/forgot-password");
        }else if (num == 1){
            $location.path("/auth/sign-in");
        }
    };

我正在尝试编写一个测试用例来测试值1,2和3。 以下是迄今为止编写的测试用例代码

describe('function: changeForm',function(){
        var formNames = ['sign in form','registration form','forgot password form'],
        paths = ['/auth/sign-in','/auth/register','/auth/forgot-password'],
        num,
        currentPath;
        beforeEach(function(){
            $scope.changeForm(num);
            currentPath = $location.path();
        })

        for(num = paths.length; num >=1;num--){
            it('should make all the input fields empty and show '+formNames[num-1],function(){
                expect($scope.userEmail_sign).toBe('');
                expect($scope.pass_sign).toBe('');
                expect($scope.userEmail_reg).toBe('');
                expect($scope.npi).toBe('');
                expect($scope.password_reg).toBe('');
                expect($scope.confirmPassword_reg).toBe('');
                expect($scope.userEmail_forgotPwd).toBe('');
                expect($scope.formCode).toBe(num);
                expect(currentPath).toBe(paths[num-1]);
            });
        }
    });

对于放置的循环,当我运行测试用例时,我收到以下错误。

Expected '/auth/register' to be undefined.

我缺少什么让这项工作?

0 个答案:

没有答案