Skip to content

Instantly share code, notes, and snippets.

@cpoDesign
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cpoDesign/37b602ec02b872c6368f to your computer and use it in GitHub Desktop.
Save cpoDesign/37b602ec02b872c6368f to your computer and use it in GitHub Desktop.
Basic unit testing with angular - variable in controller
// for every module you include here, you need to add required resource files into your test file
var app = angular.module('app', ['ngSanitize', 'ngResource', 'ngRoute']);
// definition of controller
'use strict';
app.controller('AdminCtr',
function AdminCtr() {
this.helpAndSupportText = 'Hello';
});
// unit test
/// <reference path="../../../angular.js" />
/// <reference path="../../../angular-route.min.js" />
/// <reference path="../../../angular-resource.js" />
/// <reference path="../../../angular-sanitize.min.js" />
/// <reference path="../../../angular-mocks.js" />
/// <reference path="../../../app/app.js" />
/// <reference path="../../../app/controllers/adminCtr.js" />
'use strict';
describe('adminCtrSpec', function () {
var adminCtr;
beforeEach(module("app"));
beforeEach(inject(function($controller) {
adminCtr = $controller("AdminCtr");
}));
describe('AdminCtrl', function() {
it('should have a message hello', function() {
expect(adminCtr.helpAndSupportText).toBe("Hello");
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment