angular
.module('app.cars')
- .controller('CarsErrorModal', CarsErrorModal);
+ .controller('CarsErrorModalController', CarsErrorModalController);
/**
* @ngdoc controller
- * @name app.cars.controller:CarsErrorModal
+ * @name app.cars.controller:CarsErrorModalController
*
* @requires $modalInstance
* @requires app.cars.cars
* Controller for error modal in cars application.
*/
/* @ngInject */
- function CarsErrorModal($modalInstance, cars) {
+ function CarsErrorModalController($modalInstance, cars) {
var vm = this;
vm.cars = cars;
close: jasmine.createSpy('modalInstance.close'),
dismiss: jasmine.createSpy('modalInstance.dismiss')
};
- var CarsErrorModal;
+ var CarsErrorModalController;
beforeEach(function() {
module('app.cars');
inject(function($controller) {
- CarsErrorModal = $controller('CarsErrorModal', {
+ CarsErrorModalController = $controller('CarsErrorModalController', {
$modalInstance: $modalInstance,
cars: cars
});
});
- describe('CarsErrorModal controller', function () {
+ describe('CarsErrorModalController controller', function () {
it('should invoke $modalInstance.close', function () {
- CarsErrorModal.ok();
+ CarsErrorModalController.ok();
expect($modalInstance.close).toHaveBeenCalledWith('car1');
});
it('should invoke $modalInstance.dismiss', function () {
- CarsErrorModal.cancel();
+ CarsErrorModalController.cancel();
expect($modalInstance.dismiss).toHaveBeenCalledWith('cancel');
});
angular
.module('app.cars')
- .controller('Cars', Cars);
+ .controller('CarsController', CarsController);
/**
* @ngdoc controller
- * @name app.cars.controller:Cars
+ * @name app.cars.controller:CarsController
*
* @requires $modal
* @requires $timeout
* </p>
*
* @description
- * Cars controller.
+ * CarsController controller.
*/
/* @ngInject */
- function Cars($modal, $timeout, cars) {
+ function CarsController($modal, $timeout, cars) {
var vm = this;
vm.example = {
},
// Error
function(reason) {
- console.log('Cars controller error: ' + reason);
+ console.log('CarsController controller error: ' + reason);
vm.doModal('lg');
}
);
cars.getById(1).then(
function (value) {
- console.log('getCar getById: Cars controller value: ' + JSON.stringify(value));
+ console.log('getCar getById: CarsController controller value: ' + JSON.stringify(value));
},
function(reason) {
- console.log('getCar getById: Cars controller reason: ' + JSON.stringify(reason));
+ console.log('getCar getById: CarsController controller reason: ' + JSON.stringify(reason));
}
);
cars.getExpectedValue().then(
function (value) {
- console.log('getCar getExpectedValue: Cars controller value: ' + JSON.stringify(value));
+ console.log('getCar getExpectedValue: CarsController controller value: ' + JSON.stringify(value));
},
function(reason) {
- console.log('getCar getExpectedValue: Cars controller reason: ' + JSON.stringify(reason));
+ console.log('getCar getExpectedValue: CarsController controller reason: ' + JSON.stringify(reason));
}
);
cars.getExpectedValue().then(
function (value) {
- console.log('getResolvedPromise getExpectedValue: Cars controller value: ' + JSON.stringify(value));
+ console.log('getResolvedPromise getExpectedValue: CarsController controller value: ' +
+ JSON.stringify(value));
},
function(reason) {
- console.log('getResolvedPromise getExpectedValue: Cars controller reason: ' + JSON.stringify(reason));
+ console.log('getResolvedPromise getExpectedValue: CarsController controller reason: ' +
+ JSON.stringify(reason));
}
);
var modalInstance = $modal.open({
animation: true,
templateUrl: 'app/cars/cars-error-modal.html',
- controller: 'CarsErrorModal as vm',
+ controller: 'CarsErrorModalController as vm',
size: size,
backdrop: 'static',
keyboard: false,
return {};
}
};
- var Cars;
+ var CarsController;
var $q;
beforeEach(function() {
module('app.cars');
inject(function($controller, $modal, $timeout, _$q_) {
- Cars = $controller('Cars', {
+ CarsController = $controller('CarsController', {
$modal: $modal,
$timeout: $timeout,
cars: cars
};
});
- Cars.getCars();
+ CarsController.getCars();
expect(cars.getAll).toHaveBeenCalled();
- expect(Cars.cars).toEqual(onFulfilledValue);
+ expect(CarsController.cars).toEqual(onFulfilledValue);
});
});
})
};
var $timeout;
- var Cars;
+ var CarsController;
var $q;
beforeEach(function() {
module('app.cars');
inject(function($controller, _$timeout_, _$q_) {
- Cars = $controller('Cars', {
+ CarsController = $controller('CarsController', {
$modal: $modal,
$timeout: _$timeout_,
cars: cars
it('should invoke GET all cars in service with success: alternative way', function () {
- Cars.getCars();
+ CarsController.getCars();
expect(cars.getAll).toHaveBeenCalled();
- expect(Cars.cars).toEqual(onFulfilledValue);
+ expect(CarsController.cars).toEqual(onFulfilledValue);
});
it('should invoke GET all cars in service with error: alternative way', function () {
isSuccessCallBack = false;
- spyOn(Cars, 'doModal')
+ spyOn(CarsController, 'doModal')
.and.callFake(function() {
return {};
});
- Cars.getCars();
+ CarsController.getCars();
expect(cars.getAll).toHaveBeenCalled();
- expect(Cars.doModal).toHaveBeenCalled();
+ expect(CarsController.doModal).toHaveBeenCalled();
isSuccessCallBack = true;
});
it('should invoke $modal.open', function () {
- Cars.doModal('lg');
+ CarsController.doModal('lg');
expect($modal.open).toHaveBeenCalled();
});
it('should invoke $modalInstance.result with success', function () {
- Cars.doModal('lg');
+ CarsController.doModal('lg');
expect($modalInstance.result.then).toHaveBeenCalled();
- expect(Cars.selected).toEqual(onFulfilledValue);
+ expect(CarsController.selected).toEqual(onFulfilledValue);
});
it('should invoke $modalInstance.result with error', function () {
isSuccessCallBack = false;
- Cars.doModal('lg');
+ CarsController.doModal('lg');
expect($modalInstance.result.then).toHaveBeenCalled();
it('should invoke $modalInstance.opened with success', function () {
- Cars.doModal('lg');
+ CarsController.doModal('lg');
expect($modalInstance.opened.then).toHaveBeenCalled();
it('should invoke $modalInstance.opened with error', function () {
isSuccessCallBack = false;
- Cars.doModal('lg');
+ CarsController.doModal('lg');
expect($modalInstance.opened.then).toHaveBeenCalled();
it('should invoke $modalInstance.rendered with success', function () {
- Cars.doModal('lg');
+ CarsController.doModal('lg');
expect($modalInstance.rendered.then).toHaveBeenCalled();
it('should invoke $modalInstance.rendered with error', function () {
isSuccessCallBack = false;
- Cars.doModal('lg');
+ CarsController.doModal('lg');
expect($modalInstance.rendered.then).toHaveBeenCalled();
it('should invoke $modalInstance.close because of timeout', function () {
- Cars.doModal('lg');
+ CarsController.doModal('lg');
$timeout.flush();
expect($modalInstance.close).toHaveBeenCalledWith('closed by timeout');
it('should invoke $modalInstance.dismiss because of timeout', function () {
- Cars.doModal('lg');
+ CarsController.doModal('lg');
$timeout.flush();
expect($modalInstance.dismiss).toHaveBeenCalledWith('dismissed by timeout');
<!DOCTYPE html>
<div class="container">
- <form name="myForm" ng-controller="Cars as vm">
+ <form name="myForm" ng-controller="CarsController as vm">
<label>Single word:</label>
<input type="text" name="input" ng-model="vm.example.text"
ng-pattern="vm.example.word" required ng-trim="false">
angular
.module('app.welcome')
- .controller('Welcome', Welcome);
+ .controller('WelcomeController', WelcomeController);
// When using <div ng-app="app" ng-strict-di> (strict mode) we must always
// manually identify dependencies.
// Instead I am going to use ngInject because it is cool :)
- // Welcome.$inject = ['$location'];
+ // WelcomeController.$inject = ['$location'];
/**
* @ngdoc controller
- * @name app.welcome.controller:Welcome
+ * @name app.welcome.controller:WelcomeController
*
* @requires $location
*
* </p>
*
* @description
- * Welcome controller.
+ * WelcomeController controller.
*/
/* @ngInject */
- function Welcome($location) {
+ function WelcomeController($location) {
var vm = this;
vm.hello = 'Hello World';
describe('app.welcome', function() {
'use strict';
- var controller;
- var scope;
+ var WelcomeController;
+ var $scope;
beforeEach(function() {
module('app.welcome');
inject(function($controller, _$rootScope_) {
- scope = _$rootScope_.$new();
- scope.hello = 'Hello World';
- controller = $controller('Welcome', {$scope: scope});
+ $scope = _$rootScope_.$new();
+ $scope.hello = 'Hello World';
+ WelcomeController = $controller('WelcomeController', {$scope: $scope});
});
});
- describe('Welcome controller', function () {
+ describe('WelcomeController controller', function () {
it('should be created successfully', function () {
- expect(controller).toBeDefined();
+ expect(WelcomeController).toBeDefined();
});
});
<!DOCTYPE html>
-<div class="container" ng-controller="Welcome as vm">
+<div class="container" ng-controller="WelcomeController as vm">
<div class="row">
{{ vm.hello }}
'use strict';
describe('exampleControllerAsDirective', function() {
- var compile;
- var rootScope;
+ var $compile;
+ var $rootScope;
var template;
beforeEach(module('app.widgets'));
- beforeEach(inject(function($compile, $rootScope) {
- compile = $compile;
- rootScope = $rootScope;
+ beforeEach(inject(function(_$compile_, _$rootScope_) {
+ $compile = _$compile_;
+ $rootScope = _$rootScope_;
template = '<controller-as-directive>';
}));
it('should assign min value 3', function() {
- var scope;
+ var $scope;
var element;
var vm;
- scope = rootScope.$new();
+ $scope = $rootScope.$new();
// IN THE REAL WORLD, BETTER DECLARE THE CONTROLLER RELATED TO MY DIRECTIVE IN A DIFFERENT FILE AND
// TEST THE CONTROLLER WITH ITS OWN SPEC!!!!!
// see: http://stackoverflow.com/a/15314876
- element = compile(template)(scope);
- scope.$digest();
+ element = $compile(template)($scope);
+ $scope.$digest();
vm = element.controller('controllerAsDirective');