Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unit testing 单元测试中的清晰角度模块_Unit Testing_Angularjs - Fatal编程技术网

Unit testing 单元测试中的清晰角度模块

Unit testing 单元测试中的清晰角度模块,unit-testing,angularjs,Unit Testing,Angularjs,我正在为我的AngularJS控制器做一些多用户测试,因为我的用户有不同的角色和设置。第一个总是很好,但是后续的尝试从来不会发出HTTP模拟请求的尝试,因为控制器是单例的。我是否有办法清除所有现有控制器,甚至整个角度模块设置,然后重新启动,以便执行这些类型的测试?您是否尝试过在Beforeach函数中创建控制器?这样,每次测试都会重新创建控制器 beforeEach(inject(function ($rootScope, $controller, $location) { root =

我正在为我的AngularJS控制器做一些多用户测试,因为我的用户有不同的角色和设置。第一个总是很好,但是后续的尝试从来不会发出HTTP模拟请求的尝试,因为控制器是单例的。我是否有办法清除所有现有控制器,甚至整个角度模块设置,然后重新启动,以便执行这些类型的测试?

您是否尝试过在Beforeach函数中创建控制器?这样,每次测试都会重新创建控制器

beforeEach(inject(function ($rootScope, $controller, $location) {
    root = $rootScope;
    scope = $rootScope.$new();
    location = $location;
    controller = $controller('AccountInfoController', { $scope: scope, $location:$location, customer: customer });
}));

如果想要清除模块,请尝试此代码


angular.module('app',[])

是的,这几乎就是我正在做的:var$scope=$rootScope.$new();返回{controller:$controller(controllerName,{$scope:$scope,$routeParams:routeParams |{}),scope:$scope};