让我们从控制器代码开始:
angular
.module('hc.hotelContent')
.controller('NameLocationController', nameLocationCtrlFn); //Todo change hotelDataService
nameLocationCtrlFn.$inject = ['$stateParams', 'hotelDataService'];
function nameLocationCtrlFn($stateParams, hotelDataService) {
var vm = this,
hotelId = $stateParams.hotelId;
vm.Keys = {
Name: 'Name',
Street: 'Street',
City: 'City',
State: 'State',
Zip: 'Zip',
Country: 'Country'
}
}
Run Code Online (Sandbox Code Playgroud)
我确实有更多的代码,但它的相关逻辑,我没有将$ stateParmas注入控制器时我的测试工作正常.
所以继承测试文件:
describe('nameLocation component Controller', function () {
var $controller,
hotelDataServiceMock,
stateParams,
hotelId = "4611";
Keys = {
Name: 'Name',
Street: 'Street',
City: 'City',
State: 'State',
Zip: 'Zip',
Country: 'Country'
}//@
beforeEach(module('hc.hotelContent'));
beforeEach(module('hc.app.core'));
beforeEach(inject(injectFn));
function injectFn(_$controller_, $stateParams, _hotelDataService_) { …Run Code Online (Sandbox Code Playgroud)