我是单元测试和AngularJS的新手,我有一些问题我无法解决。我的一个测试不起作用。我试图通过影响一个值在我的测试中启动location.path(),但在我的控制器中,location.path()仍然有一个未定义的值。
这里是我的CONTROLER:
angular.module('...')
.controller('SignUpCtrl', ['$location', function ($location) {
// Retrieve type of user
var userType = $location.path().substr(9);
if(userType == 'member'){
userType = 'user';
}
console.log($location.path());
console.log(userType);
$scope.uType = userType; ]);
这里是我的测试模块:
describe('Controller: SignUpCtrl', function() {
// load the controller's module
beforeEach(module('...'));
var SignUpCtrl,
scope,
mockBackend,
environments,
location,
store;
beforeEach(inject(function ($controller, $rootScope, $httpBackend,$location,_Environments_) {
environments = _Environments_;
mockBackend = $httpBackend;
location = $location;
scope = $rootScope.$new();
SignUpCtrl = $controller('SignUpCtrl', {
$scope: scope,
$location: location
});
}));
it('should come from the right location', function(){
location.path('/sign-up/member');
expect(location.path()).toBe('/sign-up/member');
expect(scope.uType).toBe('user'); //Do not work
});
});
感谢您的回应我会看看E2E测试,因为它仍然让我非常困惑在单元测试中测试什么以及E2E中的什么... – user2876974