茉莉花测试失败,未定义不是函数(评估 $browser

jasmine test fails with undefined is not a function(evaluating $browser.$$checkUrlChange())(茉莉花测试失败,未定义不是函数(评估 $browser.$$checkUrlChange()))
本文介绍了茉莉花测试失败,未定义不是函数(评估 $browser.$$checkUrlChange())的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下控制器:

.controller('ProjectUserAddCtrl', ['$scope', 'ProjectUser', '$q', 'i18nNotifications',     
function($scope, ProjectUser, $q, i18nNotifications) {
    var buildUnassignedUsers = function(users, project) {
        var unassignedUsers = [];
        angular.forEach(users, function(user) {
            var match;
            angular.forEach(project.projectUsers, function(projectUser) {
                if(match) {return;}
                if(projectUser.user.id === user.id) {
                    match = true;
                }
            });

            if(!match) {
                unassignedUsers.push(user);
            }
        });

        $scope.unassignedUsers = unassignedUsers;
    };     

    $q.all([
            $scope.users,
            $scope.project
    ]).then(function(result) {
            buildUnassignedUsers($scope.users, $scope.project);
            $scope.$watch('project', function(newVal) { 
                buildUnassignedUsers($scope.users, $scope.project); }, true
            );
    });
}]);

在茉莉花中进行以下测试:

And a following test in jasmine:

describe('ProjectUserAddCtrl', function() {
    var ctrl;
    beforeEach(function(){
        $scope.users = [];
        $scope.project = {
            projectUsers: []
        };
        ctrl = $controller('ProjectUserAddCtrl', {$scope:$scope, ProjectUser:ProjectUser, $q:$q, i18nNotifications:i18nNotifications});
    });

    it('should create a new instance', function() {
        expect(ctrl).toBeDefined();
    });

    // this test fails!
    it('should create a list of unassigned users', function() {
        $scope.$apply(); // need to call apply to resolve promises
        expect($scope.unassignedUsers).toBeDefined();
    });

});

'should create a list of unassigned users' 测试失败并出现此错误:

'should create a list of unassigned users' test fails with this error:

TypeError: 'undefined' is not a function(评估 $browser.$$checkUrlChange())

TypeError: 'undefined' is not a function(evaluating $browser.$$checkUrlChange())

我真的不知道为什么.任何帮助表示赞赏.

I really have no idea why. Any help appreciated.

推荐答案

这个问题出现在 angular.js 和 angular-mocks.js 不匹配时,请确保两个文件的版本相同.

It seems this issue happens when you have mismatch between angular.js and angular-mocks.js Make sure the two files are of the same version.

请忽略我对该问题的原始评论

Please ignore my original comment to the question

这篇关于茉莉花测试失败,未定义不是函数(评估 $browser.$$checkUrlChange())的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Update another component when Formik form changes(当Formik表单更改时更新另一个组件)
Formik validation isSubmitting / isValidating not getting set to true(Formik验证正在提交/isValiating未设置为True)
React Validation Max Range Using Formik(使用Formik的Reaction验证最大范围)
Validation using Yup to check string or number length(使用YUP检查字符串或数字长度的验证)
Updating initialValues prop on Formik Form does not update input value(更新Formik表单上的初始值属性不会更新输入值)
password validation with yup and formik(使用YUP和Formick进行密码验证)