Skip to content

Instantly share code, notes, and snippets.

@citizenmatt
Created April 7, 2014 10:46
Show Gist options
  • Save citizenmatt/10018143 to your computer and use it in GitHub Desktop.
Save citizenmatt/10018143 to your computer and use it in GitHub Desktop.
Angular tests with beforeEach and inject
/// <reference path="angular.js"/>
/// <reference path="angular-mocks.js"/>
/// <reference path="~/app/myApp.js"/>
describe("The moviesCtrl", function () {
'use strict';
// this is useful - will cause the browser running the tests for ReSharper
// to pause in the debugger, then using the normal dev tools, see what
// scripts are loaded, and (importantly) in what order
// debugger;
beforeEach(module("myApp"));
it("can be created", inject(function ($controller) {
var scope = {};
var ctrl = $controller("moviesCtrl", {
$scope: scope
});
expect(ctrl).toBeDefined();
}));
});
describe("The moviesCtrl scope", function () {
'use strict';
var scope;
beforeEach(module("myApp"));
beforeEach(inject(function ($controller) {
scope = {};
$controller("moviesCtrl", {
$scope: scope
});
}));
it("has a newMovie object", function () {
expect(scope.newMovie).toEqual({ Title: "" });
});
it("has a addMovie function", function () {
expect(typeof scope.addMovie).toBe("function");
});
});
@citizenmatt
Copy link
Author

When running tests in ReSharper, I don't believe it's possible to have cross-project references - i.e. the JS scripts in one VS project, and the production scripts in another. This file needs to live in the same project as the production code.

Also, jasmine.js is included by ReSharper by default, as the first script. You can change the ordering by adding a new reference xml doc node for jasmine.js wherever you want it to be.

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