I have 2 controllers - main and vendor. main.controller successfully logs in my unit test, while vendor.controller gives me an undefined error with the exact same unit test.
unit test
describe('controllers', () => {
let vm;
beforeEach(angular.mock.module('thcmaps-ui'));
beforeEach(inject(($controller) => {
vm = $controller('MainController'); // This logs correctly but errors when changed to VendorController
//vm = $controller('VendorController');
}));
it('should call stateManagerService when current name is main', () => {
console.log(vm);
expect(1).toEqual(1);
});
});
I don't know if it's a routing issue or something completely different...
index.route.js
export function routerConfig($stateProvider, $urlRouterProvider) {
'ngInject';
$stateProvider
//mobile
.state('main', {
url : '/',
templateUrl : 'app/main/main.html',
controller : 'MainController',
controllerAs: 'main',
resolve : {
location : function(userDataService){
return userDataService.getLocation()
.then(function(data){
return data;
});
}
}
})
.state('mobile', {
url : '/m/',
templateUrl : 'app/main/main.html',
controller : 'MainController',
controllerAs: 'main',
resolve : {
location : function(userDataService){
return userDataService.getLocation()
.then(function(data){
return data;
});
}
}
})
.state('mobile.vendor', {
url : 'v/:slug',
templateUrl : 'app/vendor/vendor.html',
controller : 'VendorController',
controllerAs : 'vendor',
resolve : {
data : function($stateParams, vendorDataService){
return vendorDataService.getVendor($stateParams.slug)
.then((vendor) =>{
return vendor;
})
.catch(()=>{
//todo error handling
//console.log(error);
})
},
location : function(userDataService){
return userDataService.getLocation()
.then(function(data){
return data;
});
}
}
})
//desktop
.state('map.vendor', {
url : 'v/:slug',
templateUrl : 'app/vendor/vendor.html',
controller : 'VendorController',
controllerAs : 'vendor',
resolve : {
data : function($stateParams, vendorDataService){
return vendorDataService.getVendor($stateParams.slug)
.then((vendor) =>{
return vendor;
})
.catch(()=>{
//todo error handling
//console.log(error);
})
},
location : function(userDataService){
return userDataService.getLocation()
.then(function(data){
return data;
});
}
}
});
$urlRouterProvider.otherwise('/');
}
Aucun commentaire:
Enregistrer un commentaire