Skip to content

Instantly share code, notes, and snippets.

@alexeygolev
Created August 14, 2012 01:47
Show Gist options
  • Save alexeygolev/3345655 to your computer and use it in GitHub Desktop.
Save alexeygolev/3345655 to your computer and use it in GitHub Desktop.
angular.js jasmine test spec for controller defined inside a module
'use strict';
/* jasmine specs for controllers go here */
describe('PhoneCat controllers', function() {
describe('PhoneListCtrl', function() {
beforeEach(module('phonesCat.controllers'));
var ctrl, scope;
beforeEach(inject(function($controller, $rootScope) {
scope = $rootScope.$new();
ctrl = $controller('PhoneListCtrl', {
$scope: scope
});
}));
it('should create "phones" model with 3 phones', function() {
expect(scope.phones.length).toBe(3);
});
});
});
@deanapeterson
Copy link

Question...

beforeEach(module('phonesCat.controllers'));

What type of 'module' is being referred to here?

I'm just starting to get into testing and the work 'modules' get's thrown around a lot.

@cfernandomaciel
Copy link

In this case it's a controller. In angularjs anything is treated as a module: a controller is a module, just like a service and a directive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment