'u kullanan bir denetleyiciyi sınama İşlemi tanımlamak için $routeParams
kullanan bir Denetleyiciyi test etmem gerekiyor. Belki bir test problemidir, ya da kontrol cihazını yazdığım gibi yanlış, şimdi bir test yapamam. sağlanan bir kimlik başka boş bir kaynak oluşturmak, $routeParams
iseAçısal RouteParams
İşte
angular.module('cmmApp')
.controller('UserCtrl', function ($scope, $location, $routeParams, $ionicLoading, $ionicPopup, Userservice) {
//if a user id is set retrieve user information
if(typeof $routeParams.id !== 'undefined'){
var loader = $ionicLoading.show({content: "Retrieving user data"});
var user = Userservice.get({id: $routeParams.id}).$promise;
user.then(function(res){
console.log(res);
$scope.user = res.user;
loader.hide();
});
}
//else create an empty resource
else {
$scope.user = new Userservice;
}
});
Temelde sadece bir kaynak yüklenmeye istiyorum benim denetleyicisi olduğunu. Benim bir testten önceki $routeParams.id
değiştirmek için karma anlatmak ve nasıl atanacağı wonering ediyorum
Controller: UserCtrl should create an epmty user FAILED
Expected { } to equal { }.
Error: Expected { } to equal { }.
at null.<anonymous> (/Users/carlopasqualicchio/Sites/CMM_Ionic/test/spec/controllers/user.js:28:24)
: Ben grunt test
karma cevap çalıştırdığınızda
'use strict';
describe('Controller: UserCtrl', function() {
// load the controller's module
beforeEach(module('cmmApp'));
var UserCtrl,
scope,
routeParams;
// Initialize the controller and a mock scope
beforeEach(inject(function ($controller, $rootScope, $routeParams, Userservice) {
scope = $rootScope.$new();
routeParams = $routeParams;
UserCtrl = $controller('UserCtrl', {
$scope: scope
});
console.log("routeParams");
routeParams = {id: 8490394};
console.warn(routeParams);
}));
it('should create an epmty user', function() {
console.log(scope.user);
expect(scope.user).toEqual({});
});
});
: Burada
Ve
testtir iki farklı testte farklı bir değer (bunu ilk olarak null olarak, diğerine bir değere ayarlamalıyım).Herhangi bir yardım için teşekkür ederiz.
Teşekkürler Matt.
Sen ikinci argümanı kullanarak özel$routeParams
nesneyi geçirebilir
Eğer $ routeParams.id' 'bir değer atama denediniz ? –