我正在尝试将我的angularjs应用程序从v1.6.9迁移到v1.7.8。我的测试用例失败
angular-mock.js($ rootScope)
错误:未定义响应!在angularjs / angular-mocks.js(1607)
错误:$ rootScope:INPROG
因为我是茉莉业因测试的新手,所以我尝试使用$ rootscope.flush()。但是我无法解决它。
这是我第一次使用Angularjs和茉莉花因果(jasmine karma)进行单元测试,无法找到确切原因,我也阅读了其他版本的发行说明。
使用$ rootScope我发现他们已将其范围修改为非通用函数。
以下是我的spec.js: $ rootscope,flush()出现错误。可以帮我解决这个问题吗?
$httpBackend.when('GET','/application/api/prefernce-definition')
.respond(successResponsePrefernces);
$httpBackend.when('POST','/application/api/setprefernce-definition')
.respond(201);
$httpBackend.when('POST','/application/api/v1/set-prefernces');
$httpBackend.when('POST','/application/api/v2/balances')
.respond(accountApiResponse);
//assertion for expecting proper get request for preferences-definition
$httpBackend.expectGET(,'/application/api/v1/prefernce-prefernces');
//fetch and set prefernces
$scope.onclickSetting();
$rootScope.flush();
$timeout.flush();
//now save the settings
$scope.saveViewSettings();
// getting error in this line after the flush
$rootScope.flush();
$timeout.flush();
var viewMode = $scope.model.viewSettings.viewMode,
viewModeExpected = successResponsePreferences.preferenceDefinitionList[0];
expect(viewMode.default).toBe(viewModeExpected.defaultPreferenceValue);
expect(viewMode.selected).toBe(viewModeExpected.currentUserPreferenceValue);
expect($scope.$broadcast).toHaveBeenCalledWith("ShowFilter");
//should update the prefernces in cache
expect(viewMode.selected).toBe(cacheService.getPreferences().viewMode);
expect(analyticsService.sendAction).toHaveBeenCalledwith(
Constant.ACCOUNT_BALANCES.MODULE_NAME,
Constant.ACCOUNT_BALANCES,VIEW_SETTINGS,
[]
);
expect(analyticsService.sendAction).toHaveBeenCalledwith(
Constant.ACCOUNT_BALANCES.MODULE_NAME,
Constant.ACCOUNT_BALANCES,VIEW_SETTINGS,
[Constant.EXTD_MODE, Constant.NO_GROUPING]
);
});
以下是错误:
错误:未定义响应!在 ../ bower_components / angular-mocks / angular-mocks.js(第1607行)$ httpBackend @ / .. / bower_components / angular-mocks / angular-mocks.js:1607:63。