本文介紹了茉莉花測試失敗,未定義不是函數(評估 $browser.$$checkUrlChange())的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
我有以下控制器:
.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())的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!