Skip to content

Instantly share code, notes, and snippets.

@tonyjoanes
Created November 13, 2015 16:07
Show Gist options
  • Save tonyjoanes/e8a08c2a8d9266365ad0 to your computer and use it in GitHub Desktop.
Save tonyjoanes/e8a08c2a8d9266365ad0 to your computer and use it in GitHub Desktop.
Jasmine sample controller test spec
/// <reference path="../MvcAngularJasmineTests/Scripts/angular.js"/>
/// <reference path="../MvcAngularJasmineTests/Scripts/angular-route.js"/>
/// <reference path="Scripts/angular-mocks.js"/>
/// <reference path="../MvcAngularJasmineTests/Scripts/app/app.js"/>
/// <reference path="../MvcAngularJasmineTests/Scripts/home/home.controller.js"/>
/// <reference path="Scripts/jasmine/jasmine.js"/>
describe('When working with the home.controller', function () {
var sut;
beforeEach(module("SampleApp"));
beforeEach(inject(function ($controller) {
sut = $controller('HomeController');
}));
describe('object definition tests', function () {
it('Should be defined', function () {
expect(sut).toBeDefined();
});
});
function test(testCase) {
it(testCase.it, function () {
expect(sut[testCase.object]).toBeDefined();
});
}
var testCases = [
{ it: 'Should define sampleText', object: 'sampleText' },
{ it: 'Should define pageTitle', object: 'pageTitle' }
];
describe('property definitions', function () {
angular.forEach(testCases, function (testCase) {
test(testCase);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment