I would like to testing my controller, i have used 'controller as' in the app, now i am sh*ting myself over testing.
Controller: (half of my controller)
(function(){
angular.module('donateApp')
.controller('MainCtrl', mainCtrl);
mainCtrl.$inject = ['donateFactory', 'donateService', '$location'];
function mainCtrl(donateFactory, donateService, $location){
var vm = this,
checked = false;
vm.submitted = false;
vm.submitingForm = false;
vm.amounts = [
5, 10, 25, 50, 100
];
vm.regions = donateService.getRegion();
vm.states = donateService.getStates();
Testing: 'use strict';
describe('Controller: MainCtrl', function () {
// load the controller's module
beforeEach(module('donateApp'));
var MainCtrl,
scope;
// Initialize the controller and a mock scope
beforeEach(inject(function ($controller, $rootScope) {
scope = $rootScope.$new();
MainCtrl = $controller('MainCtrl as ctrl', {
$scope: scope
});
$scope.ctrl = MainCtrl;
}));
it('Expect the form start with submitted as false', function () {
expect(MainCtrl.ctrl.submitted).toBeTruthy();
})
});
Error message i am getting:
TypeError: 'undefined' is not an object (evaluating 'MainCtrl.ctrl')
at /Applications/MAMP/htdocs/test/spec/controllers/main.js:22
I know it must be a small fix to make it work... anyone can help?
Thanks heaps
Aucun commentaire:
Enregistrer un commentaire