});
- describe('CarsErrorModalController controller', function () {
+ describe('CarsErrorModalController', function () {
it('should invoke $modalInstance.close', function () {
CarsErrorModalController.ok();
});
});
- describe('Cars controller', function () {
+ describe('CarsController', function () {
it('should invoke GET all cars in service with success: old fashionable way', function () {
});
});
- describe('Cars controller', function () {
+ describe('CarsController', function () {
it('should invoke GET all cars in service with success: alternative way', function () {
* </p>
*
* @description
- * Users controller.
+ * UsersChildController controller.
*/
/* @ngInject */
function UsersChildController($rootScope, $scope, USERS) {
vm.getEmit = function () {
$scope.$emit(USERS.SCOPE.EMIT_FACT, emitFact);
};
+ vm.usersChildOnScopeBroadcast = function (events, broadcastUser) {
+ vm.broadcastUser = broadcastUser;
+ console.log('usersChildOnScopeBroadcast, events.name: ' + events.name);
+ };
// NEVER USE $rootScope.$on IN CONTROLLER BECAUSE IT IS NOT DESTROYED EVEN IF CONTROLLER WAS DESTROYED!!!
// YOU WILL END UP HAVING AS MANY EVENT LISTENERS AS TIMES THIS CONTROLLER IS CREATED!!!!
// LISTENING FOR EVENTS IN $scope IS THE RIGHT THING BECAUSE THESE EVENT LISTENERS ARE DESTROYED
// AT THE SAME TIME AS THIS CONTROLLER :)
- $scope.$on(USERS.ROOTSCOPE.BROADCAST, usersChildOnScopeBroadcast);
+ $scope.$on(USERS.ROOTSCOPE.BROADCAST, vm.usersChildOnScopeBroadcast);
// function usersChildOnRootBroadcast(events, broadcastUser) {
// vm.broadcastUser = broadcastUser;
// console.log('usersChildOnRootBroadcast, events.name: ' + events.name);
// }
- function usersChildOnScopeBroadcast(events, broadcastUser) {
- vm.broadcastUser = broadcastUser;
- console.log('usersChildOnScopeBroadcast, events.name: ' + events.name);
- }
-
}
})();
--- /dev/null
+describe('app.users', function() {
+ 'use strict';
+
+ var $rootScope;
+ var $scope;
+ var USERS;
+ var UsersChildController;
+
+ beforeEach(function() {
+ module('app.users');
+
+ inject(function($controller, _$rootScope_, _USERS_) {
+ $rootScope = _$rootScope_;
+ USERS = _USERS_;
+ $scope = $rootScope.$new();
+
+ spyOn($scope, '$emit');
+ UsersChildController = $controller('UsersChildController', {
+ $rootScope: $rootScope,
+ $scope: $scope,
+ USERS: _USERS_
+ });
+ });
+ });
+
+ describe('UsersChildController', function () {
+
+ it('should be created successfully', function () {
+ expect(UsersChildController).toBeDefined();
+ });
+
+ it('should be called $scope.$emit', function () {
+ var emitFact = {
+ title: 'Snake and Scarlett',
+ fact: 'it is canon'
+ };
+
+ UsersChildController.getEmit();
+
+ expect($scope.$emit).toHaveBeenCalledWith(USERS.SCOPE.EMIT_FACT, emitFact);
+ });
+
+ it('should be assigned broadcastUser', function () {
+ var rootScopeBroadcastUser = {
+ name: 'Snake',
+ lastName: 'Eyes',
+ city: 'classified'
+ };
+ var event = {
+ name: 'USERS.ROOTSCOPE.BROADCAST'
+ };
+
+ UsersChildController.usersChildOnScopeBroadcast(event, rootScopeBroadcastUser);
+
+ expect(UsersChildController.broadcastUser).toEqual(rootScopeBroadcastUser);
+ });
+ });
+
+});
vm.getScopeBroadcast = function () {
$scope.$broadcast(USERS.ROOTSCOPE.BROADCAST, scopeBroadcastUser);
};
-
- $scope.$on(USERS.SCOPE.EMIT_FACT, usersOnEmitFact);
-
- function usersOnEmitFact(events, emitFact) {
+ vm.usersOnEmitFact = function (events, emitFact) {
vm.emitFact = emitFact;
console.log('usersOnEmitFact, events.name: ' + events.name);
- }
+ };
+
+ $scope.$on(USERS.SCOPE.EMIT_FACT, vm.usersOnEmitFact);
}
})();
USERS = _USERS_;
$scope = $rootScope.$new();
- jasmine.createSpy($rootScope, '$rootScope.$broadcast');
+ spyOn($rootScope, '$broadcast');
jasmine.createSpy($scope, '$scope.$broadcast');
UsersController = $controller('UsersController', {
$rootScope: $rootScope,
});
});
- describe('UsersController controller', function () {
+ describe('UsersController', function () {
it('should be created successfully', function () {
expect(UsersController).toBeDefined();
expect($scope.$broadcast).toHaveBeenCalledWith(USERS.ROOTSCOPE.BROADCAST, scopeBroadcastUser);
});
+
+ it('should be assigned emitFact', function () {
+ var emitFact = {
+ title: 'Snake and Scarlett',
+ fact: 'it is canon'
+ };
+ var event = {
+ name: 'USERS_SCOPE_EMIT_FACT'
+ };
+
+ UsersController.usersOnEmitFact(event, emitFact);
+
+ expect(UsersController.emitFact).toEqual(emitFact);
+ });
});
});
});
});
- describe('WelcomeController controller', function () {
+ describe('WelcomeController', function () {
it('should be created successfully', function () {
expect(WelcomeController).toBeDefined();