0
我試圖建立測試離子項目離子控制器,我有我的控制器測試如下:噶/茉莉不會注入
describe('ShopsCtrl', function() {
var controller;
beforeEach(module('shoplocal'));
it('should foo', function() {
expect(true).toBe(true);
});
beforeEach(angular.mock.inject(function($controller) {
// instantiate shop controller
controller = $controller('ShopsCtrl');
}));
it('foo should be bar', function() {
expect(controller.foo).toBe('bar');
});
})
應用程序定義如下:
(function() {
shoplocalRun.$inject = ['$ionicPlatform', '$rootScope'];
function shoplocalRun($ionicPlatform, $rootScope) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
cordova.plugins.Keyboard.disableScroll(true);
}
if (window.StatusBar) {
StatusBar.overlaysWebView(true);
StatusBar.style(1);
}
});
}
angular.module('shoplocal', ['ionic', 'ngCordova'])
.run(shoplocalRun);
})();
控制器是在網絡/應用/店/ shopsCtrl.js一個單獨的文件:
(function() {
ShopsCtrl.$inject = [];
function ShopsCtrl() {
var vm = this;;
vm.foo = "bar";
}
angular.module('shoplocal')
.controller('ShopsCtrl', ShopsCtrl);
})();
但是當我運行測試,我得到的來回m業力是:
PhantomJS 2.1.1 (Mac OS X 0.0.0) ShopsCtrl should foo FAILED
/Users/ospfranco/marcus/ShopLocal-Ionic/www/lib/ionic/js/ionic.bundle.js:17698:53
[email protected]/Users/ospfranco/marcus/ShopLocal-Ionic/www/lib/ionic/js/ionic.bundle.js:13648:24
[email protected]/Users/ospfranco/marcus/ShopLocal-Ionic/www/lib/ionic/js/ionic.bundle.js:17658:12
[email protected]/Users/ospfranco/marcus/ShopLocal-Ionic/www/lib/ionic/js/ionic.bundle.js:17584:22
[email protected]/Users/ospfranco/marcus/ShopLocal-Ionic/bower_components/angular-mocks/angular-mocks.js:2393:60
PhantomJS 2.1.1 (Mac OS X 0.0.0) ShopsCtrl foo should be bar FAILED
/Users/ospfranco/marcus/ShopLocal-Ionic/www/lib/ionic/js/ionic.bundle.js:17698:53
[email protected]/Users/ospfranco/marcus/ShopLocal-Ionic/www/lib/ionic/js/ionic.bundle.js:13648:24
[email protected]/Users/ospfranco/marcus/ShopLocal-Ionic/www/lib/ionic/js/ionic.bundle.js:17658:12
[email protected]/Users/ospfranco/marcus/ShopLocal-Ionic/www/lib/ionic/js/ionic.bundle.js:17584:22
[email protected]/Users/ospfranco/marcus/ShopLocal-Ionic/bower_components/angular-mocks/angular-mocks.js:2393:60
TypeError: undefined is not an object (evaluating 'controller.foo') in /Users/ospfranco/marcus/ShopLocal-Ionic/tests/unit-tests/shops.controller.tests.js (line 27)
/Users/ospfranco/marcus/ShopLocal-Ionic/tests/unit-tests/shops.controller.tests.js:27:22
任何想法是怎麼回事?