Service Injection to test controller jasmin - angularjs

Newest Update
My service or factory can still not be found.
'use strict';
/* jasmine specs for controllers go here */
describe("Backpage Controller", function(){
describe('Root Ctrl', function() {
var scope, ctrl, myService;
beforeEach(module("backpageApp"));
beforeEach(inject(function(Data, $controller, $rootScope) {
myService = Data;
scope = $rootScope.$new();
ctrl = $controller("RootCtrl", {$scope:scope});
}));
it('should set the default value of orderProp model', function() {
expect(scope.orderProp).toBe('rent')
});
it('should create "listings" model with 10 listings', function() {
expect(myService.listings.length).toBe(10)
});
});
});
This is the newest error.
Chrome 32.0.1700 (Mac OS X 10.8.4) Backpage Controller Root Ctrl should create "listings" model with 10 listings FAILED
TypeError: Cannot read property 'length' of undefined
at null.<anonymous> (/Users/judyngai/Desktop/Jan2014/newback/trynewversion/minibackpage/test/unit/controllersSpec.js:24:32)
Chrome 32.0.1700 (Mac OS X 10.8.4): Executed 2 of 2 (1 FAILED) (0.284 secs / 0.058 secs)
my services.js file contain this, I am using the angular seed project.
angular.module('backpage.services', [])
.factory('Data', function($resource) {
return $resource('data/data.json');
});
my app.js file is this
var backpageApp = angular.module('backpageApp', ['ui.router', 'ngResource', 'ngRoute','backpage.services', 'backpagecontrollers']);
I am very new to angular js. I am trying to write a jasmin spec that test my RootCtrl.
I created a service to share between controllers
angular.module('backpage.services', [])
.factory('Data', function($resource) {
return $resource('data/data.json');
});
I injected the module above to my application level module.
The RootCtrl has a 'Data' parameter given to its function so the scope object can access the shared data.json fetched by $resource.
I set this to the Data in the Root Ctrl
$scope.listings = Data.query();
Now I am having trouble figuring out how to inject the service I created to my spec written in jasmin.
My Jasmin file currently looks something like this
describe("Backpage Controller", function(){
describe('Root Ctrl', function() {
var scope, ctrl;
beforeEach(module("backpageApp"));
var $injector = angular.injector(['backpageApp']);
var myService = $injector.get('backpage.services');
beforeEach(inject(function($controller, $httpBackend) {
scope = {};
ctrl = $controller("RootCtrl", {$scope:scope});
}));
it('should set the default value of orderProp model', function() {
expect(scope.orderProp).toBe('rent')
});
it('should create "listings" model with 10 listings', function() {
expect(myService.listings.length).toBe(10)
});
});
});
I am currently getting this error when I run the jasmin test
Chrome 32.0.1700 (Mac OS X 10.8.4) Backpage Controller Root Ctrl encountered a declaration exception FAILED
Error: [$injector:unpr] Unknown provider: backpage.servicesProvider <- backpage.services
I have taken a look at the testing examples on angular js official documentation, the sample uses
$httpBackend
in the jasmin code to grab the json file but the $httpBackend doc says its use with $http service but I am using resource.
Also the data.json contain 10 listings of advertisements.
any help is appreciated.

When you run beforeEach(module("backpageApp")); angular-mocks loads all the dependencies automatically and allow you to inject them as in regular applications (not tests)
You also need to create a scope with $rootScope:
var scope, ctrl, myService;
beforeEach(module("backpageApp"));
beforeEach(inject(function(Data, $controller, $httpBackend, $rootScope) {
myService = Data;
scope = $rootScope.$new();
ctrl = $controller("RootCtrl", {$scope:scope});
}));

I figured it out I should just use $httpBackend from angular js to fetch the data.json file.
I have this as a variable httpBackend
I injected this into $httpBackend
httpBackend.when('GET', 'data/data.json').respond([{id: 1 }, {id: 2}, {id:3}, {id:4}, {id:5}, {id:6}, {id:7}, {id:8}, {id:9}, {id:10}]);
and flush it back out
httpBackend.flush();
for testing purposes

Related

Unit testing angular.js service (node.js server) in controller

I'm new to the unit testing in the client side. My application uses the express.js, angularjs-ui-router and node.js. Currently i start writing the unit test cases for the application. I'm using Karma, Mocha, Chai, Sinon for unit testing.
My router config look like below:
$stateProvider
.state('drive', {
url: '/drive',
templateUrl: 'drive.jade',
controller: 'driveCtrl',
});
Controller:
angular.module('mApp').controller('driveCtrl', ['$scope', 'driveService',
function($scope, driveService) {
var driveInfo = driveService.get({}, function() {});
driveInfo.$promise.then(function(rs) {
var drivers = [];
//Logical operation
$scope.drivers = drivers;
});
}]);
Factory Resource:
mApp.factory('driveService', ['$resource', function($resource) {
return $resource('/drive/id/:id/', {id:'#id'});
}]);
The driveService is a factory which insides uses a angular.js $resources. I tried variety of options but nothings seems to be working (using the $httpbackend, $q). Can you help me out to write the way to test the controller by mocking the driveService.
Here's my unit test code:
var expect = require('chai').expect;
var sinon = require('sinon');
describe('Drive Service initialisation', function() {
var scope, controller, state, $q, mockDriveService, driveServiceResponse = [{name:'james', type: 'heavy'}], queryDeferred;
beforeEach(angular.mock.module('mApp'));
angular.mock.module(function($provide){
$provide.value('driveService', mockDriveService);
});
describe(' drive service called', function() {
beforeEach(inject(function($controller, $rootScope, $state, _$q_, driveService) {
$q = _$q_;
scope = $rootScope.$new();
mockDriveService = {
get:function(){
queryDeferred = $q.defer();
queryDeferred.resolve(driveServiceResponse);
return {$promise: queryDeferred.promise};
}
};
controller = $controller('driveCtrl', { $scope: scope, driveService:driveService});
sinon.stub(mockDriveService, 'get');
scope.$apply();
}));
it('expect filter to be empty', function () {
expect(scope.drivers).to.not.be.empty;
});
});
});
The error what i'm getting is:
Error: Unexpected request: GET /driveService/id
No more request expected
at $httpBackend (node_modules/angular-mocks/angular-mocks.js:1210:9)
at sendReq (public/javascripts/lib/angular/angular.js:10333:9)
at serverRequest (public/javascripts/lib/angular/angular.js:10045:16)
at processQueue (public/javascripts/lib/angular/angular.js:14567:28)
at public/javascripts/lib/angular/angular.js:14583:27
at Scope.$eval (public/javascripts/lib/angular/angular.js:15846:28)
at Scope.$digest (public/javascripts/lib/angular/angular.js:15657:31)
at Scope.$apply (public/javascripts/lib/angular/angular.js:15951:24)
at Context.<anonymous> (C:/Users/por/AppData/Local/Temp/b0475694b46e0d60262621ad126ce46c.browserify:63:9)
at Object.invoke (public/javascripts/lib/angular/angular.js:4450:17)
Error: Declaration Location
at window.inject.angular.mock.inject (node_modules/angular-mocks/angular-mocks.js:2375:25)
You're defining a mocked service but still providing unmocked driveService for controller (this has been already done by default).
The fact that driveService.get is stubbed after the controller was instantiated and the method was called, doesn't help the case.
It should be something like
mockDriveService = {
get: sinon.stub().returns({$promise: $q.resolve(driveServiceResponse)})
};
controller = $controller('driveCtrl', { $scope: scope, driveService:mockDriveService});
scope.$apply();
The app should have test-friendly design to be tested efficiently. Considering that router is loaded in top-level module and its configuration is defined there too, app units that are supposed to be tested should be defined in child modules, so they could be tested in isolation.
The app may be refactored as
angular.module('mApp', ['ui.router', 'mApp.drive']);
...
angular.module('mApp.drive', [])
.controller('driveCtrl', ...)
.factory('driveService', ...);
And its units may be tested like
beforeEach(angular.mock.module('mApp.drive'));
...

angularjs jasmine tests: Variable vm not found

New to angular and Jasmine tests in angular. So I am writing a sample unit test to test a length of an array upon initialization in my controller. I expect the array to be of length 0. However, not sure what I am missing, the test output says that it cannot find the variable vm I am using to refer to the array. Here is my test:
(function(){
'use strict';
describe('Testing UploadedReleasesController', function() {
beforeEach(module('app.uploadedReleases'));
describe('Testing uploaded releases controller', function(){
var vm, controller;
beforeEach(inject(function($controller, $rootScope){
vm = $rootScope.$new();
controller = $controller('UploadedReleasesController', {$scope:vm});
}));
});
describe('album length', function(){
it('it should test album length', function () {
expect(vm.albums).toBeDefined();
expect(vm.albums.length).toBe(0);
});
});
});
})();
Output: Testing UploadedReleasesController album length it should test album length FAILED
ReferenceError: Can't find variable: vm
Any suggestions ?
EDIT
After other responses, I modified my .spec file and the error of vm not being able to find goes away. But now I have a different error. Here is the updated code:
(function(){
'use strict';
describe('Testing UploadedReleasesController', function() {
var scope, controller;
beforeEach(inject(function($controller, $rootScope){
scope = $rootScope.$new();
controller = $controller('UploadedReleasesController', {$scope:scope});
}));
beforeEach(module('app.uploadedReleases'));
describe('album length', function(){
it('it should test album length', function () {
//expect(vm.albums).toBeDefined();
expect(scope.albums.length).toBe(0);
});
});
});
})();
Error: `PhantomJS 1.9.8 (Mac OS X 0.0.0) Testing UploadedReleasesController true Should be true FAILED
Error: [ng:areq] Argument 'UploadedReleasesController' is not a function, got undefined
http://errors.angularjs.org/1.3.20/ng/areq?p0=UploadedReleasesController&p1=not%20a%20function%2C%20got%20undefined
undefined
at assertArg (/Users/rgoti/ingestion/external-ingestion/app/public/bower_components/angular/angular.js:1590)
at assertArgFn (/Users/rgoti/ingestion/external-ingestion/app/public/bower_components/angular/angular.js:1601)
at /Users/rgoti/ingestion/external-ingestion/app/public/bower_components/angular/angular.js:8493
at /Users/rgoti/ingestion/external-ingestion/app/public/bower_components/angular-mocks/angular-mocks.js:1916
at /Users/rgoti/ingestion/external-ingestion/app/public/src/app/uploadedReleases/uploaded-releases.controller.spec.js:10
at invoke (/Users/rgoti/ingestion/external-ingestion/app/public/bower_components/angular/angular.js:4219)
at workFn (/Users/rgoti/ingestion/external-ingestion/app/public/bower_components/angular-mocks/angular-mocks.js:2475)
Error: Injector already created, can not register a module!`
ANOTHER EDIT: Added Oscar's solution which makes the previous error go away. Now I have another problem. HEre is my actual controller definition:
(function (){
angular.module('app.uploadedReleases')
.controller('UploadedReleasesController', UploadedReleasesController)
.controller('ModalController', ModalController);
var ACTION = {
CANCEL: 0,
SAVE: 1,
DELETE: 2,
SUBMIT: 3
};
UploadedReleasesController.$inject = ['$log', '$scope', '$modal', 'ReleaseService', 'TrackService', 'APP_CONFIG'];
function UploadedReleasesController ($log, $scope, $modal, releaseService, trackService, APP_CONFIG){
So ModalController is not there in my spec file. Is that why I get the following error ?
`Error: [$injector:unpr] Unknown provider: $modalProvider <- $modal <- UploadedReleasesController
http://errors.angularjs.org/1.3.20/$injector/unpr?p0=%24modalProvider%20%3C-%20%24modal%20%3C-%20UploadedReleasesController
at /Users/rgoti/ingestion/external-ingestion/app/public/bower_components/angular/angular.js:4031
at getService (/Users/rgoti/ingestion/external-ingestion/app/public/bower_components/angular/angular.js:4178)
at /Users/rgoti/ingestion/external-ingestion/app/public/bower_components/angular/angular.js:4036
at getService (/Users/rgoti/ingestion/external-ingestion/app/public/bower_components/angular/angular.js:4178)
at invoke (/Users/rgoti/ingestion/external-ingestion/app/public/bower_components/angular/angular.js:4210)
at instantiate (/Users/rgoti/ingestion/external-ingestion/app/public/bower_components/angular/angular.js:4227)
at /Users/rgoti/ingestion/external-ingestion/app/public/bower_components/angular/angular.js:8524
at /Users/rgoti/ingestion/external-ingestion/app/public/bower_components/angular-mocks/angular-mocks.js:1916
at /Users/rgoti/ingestion/external-ingestion/app/public/src/app/uploadedReleases/uploaded-releases.controller.spec.js:12
at invoke (/Users/rgoti/ingestion/external-ingestion/app/public/bower_components/angular/angular.js:4219)
at workFn (/Users/rgoti/ingestion/external-ingestion/app/public/bower_components/angular-mocks/angular-mocks.js:2475)
undefined
Expected undefined to be defined.
at /Users/rgoti/ingestion/external-ingestion/app/public/src/app/uploadedReleases/uploaded-releases.controller.spec.js:22
TypeError: 'undefined' is not an object (evaluating 'vm.albums.length')
at /Users/rgoti/ingestion/external-ingestion/app/public/src/app/uploa`
Is so, how do I resolve it ?
You have to define vm earlier in the outer scope:
(function(){
'use strict';
describe('Testing UploadedReleasesController', function() {
var vm, controller;
beforeEach(module('app.uploadedReleases'));
describe('Testing uploaded releases controller', function(){
beforeEach(inject(function($controller, $rootScope){
vm = $rootScope.$new();
controller = $controller('UploadedReleasesController', {$scope:vm});
}));
});
describe('album length', function(){
it('it should test album length', function () {
expect(vm.albums).toBeDefined();
expect(vm.albums.length).toBe(0);
});
});
});
})();
Well, you're defining vmin the first describe() function, and you're using it in the second one. So it's indeed undefines. Variables are scoped to their enclosing functions.
Also, you shouldn't name a variable of type "Scope" vm. vm is typically used to refer to the current controller, not to its scope. Use... $scope.
Your two inner describe functions are at the same level as one another. The vm variable isn't in scope for the second one.
Either nest the second one inside the first. That's what I think you want. Something like this:
describe('Testing uploaded releases controller', function(){
var vm, controller;
beforeEach(inject(function($controller, $rootScope){
vm = $rootScope.$new();
controller = $controller('UploadedReleasesController', {$scope:vm});
}));
describe('album length', function(){
it('it should test album length', function () {
expect(vm.albums).toBeDefined();
expect(vm.albums.length).toBe(0);
});
});
});
Or pull the vm variable declaration outside of the first ("'Testing uploaded...") into the top level describe.
Move the beforeEach(inject.... directly inside describe('Testing UploadedReleasesController' and instantiate the variables: var vm, controller;
describe('Testing UploadedReleasesController', function() {
var vm, controller;
beforeEach(inject(....
The before each in the 'root' suite (Testing UploadedReleasesController) will be run for each test in the the inner suites. The inner suites will also have the vm, and controller variables availalbe. Additionally, I would create an afterEach function that resets the variables to undefined.
Update:
Move the 'album length' suite inside 'Testing uploaded releases controller':
(function(){
'use strict';
describe('Testing UploadedReleasesController', function() {
beforeEach(module('app.uploadedReleases'));
describe('Testing uploaded releases controller', function(){
var vm, controller;
beforeEach(inject(function($controller, $rootScope){
vm = $rootScope.$new();
controller = $controller('UploadedReleasesController', {$scope:vm});
}));
afterEach(function() {
vm = undefined;
controller = undefined;
});
describe('album length', function(){
it('it should test album length', function () {
expect(vm.albums).toBeDefined();
expect(vm.albums.length).toBe(0);
});
});
});
});
})();

I can't figure out the solution for the following error

My code of test_Spec.js
describe('Myctrl', function() {
var $httpBackend, scope, createController, authRequestHandler;
// Set up the module
beforeEach(module('myApp'));
beforeEach(inject(function($injector) {
// Set up the mock http service responses
$httpBackend = $injector.get('$httpBackend');
// backend definition common for all tests
authRequestHandler = $httpBackend.when('GET', 'http://www.w3schools.com/angular/customers.php')
.respond(true);
// Get hold of a scope (i.e. the root scope)
$rootScope = $injector.get('$rootScope');
// The $controller service is used to create instances of controllers
var $controller = $injector.get('$controller');
createController = function() {
return $controller('Myctrl', {'$scope' : scope});
};
})
);
afterEach(function() {
$httpBackend.verifyNoOutstandingExpectation();
$httpBackend.verifyNoOutstandingRequest();
});
it('should fetch authentication token', function() {
$httpBackend.expectGET('http://www.w3schools.com/angular/customers.php');
var controller = createController();
expect(scope.names).toBe(true);
$httpBackend.flush();
});
});
This is my test.js service call
var myApp = angular.module('myApp', []);
app.controller('Myctrl', function($Scope, $http) {
$http.get("http://www.w3schools.com/angular/customers.php")
.success(function(response) {$Scope.names = response.records;});
});
and these are the errors that I'm getting:
Here is a summary of the errors:
Error: [$injector:unpr] Unknown provider: $rootScopeProvider <- $rootScope <- $httpBackend http://errors.angularjs.org/1.2.0/$injector/unpr?p0=%24rootScopeProvider%20%3C-%20%24rootScope%20%3C-%20%24httpBackend
TypeError: Cannot read property 'expectGET' of undefined
TypeError: Cannot read property 'verifyNoOutstandingExpectation' of undefined
What is the solution for the errors? I have tried several things but I can't figure out the exact solution. Please assist on this.
You have a typo in your dependencies that you want to inject into your controller.
Change $Scope to $scope ;)
As for the error in your test, try injecting the services this way:
beforeEach(inject(function (_$httpBackend_, _$rootScope_, _$controller_) {
…
Well, I know it is too late to answer but in case anyone else stumbles upon similar error, you can try the following:
You never defined the scope variable. You just declared it. So it actually should be:
scope = $injector.get('$rootScope').$new();
Also note the $new(). For every new test case, (as a best practice) you should get a new scope.

Getting "Unexpected request" error when running Karma unit test in an AngularJS app

I'm trying to write a unit test for a controller which fetches article details using $http service.
Controller:
.controller('ArticleDetailCtrl',function($scope, Article, $routeParams, API_URL, ARTICLE_URL, $http, $sce){
$scope.url = API_URL + ARTICLE_URL + '/' + $routeParams.articleId;
$http.get($scope.url).then(function(response) {
//console.log(response.data);
$scope.heading = response.data.Headline;
$scope.rawBody = response.data.Body;
$scope.body = $sce.trustAsHtml($scope.rawBody);
$scope.image = response.data.Assets[0].URL;
});
});
Unit test:
'use strict';
describe('Controller: Article', function () {
var scope,
$httpBackend,
articleEndpoint;
// load the controller's module
beforeEach(module('myApp'));
describe('ArticleDetailCtrl', function () {
var ArticleDetailCtrl,
jsonObject,
ArticleId = '123';
// Initialize the controller and a mock scope
beforeEach(inject(function ($controller, $rootScope, _$httpBackend_, Article, API_URL, ARTICLE_URL) {
scope = $rootScope.$new();
ArticleDetailCtrl = $controller('ArticleDetailCtrl', { $scope: scope });
$httpBackend = _$httpBackend_;
articleEndpoint = API_URL + ARTICLE_URL + '/' + ArticleId;
jsonObject = {
'Headline': 'Headline',
'Body': '<p>Body</p>',
'Assets': [
{
'URL': 'path/to/image/article1.jpg'
}
]
};
$httpBackend.when('GET', articleEndpoint).respond(jsonObject);
}));
afterEach(function() {
$httpBackend.verifyNoOutstandingExpectation();
$httpBackend.verifyNoOutstandingRequest();
});
it('should fetch article details from the API', function () {
//expect(scope.articles.length).toEqual(3);
$httpBackend.expectGET(articleEndpoint);
$httpBackend.flush();
});
});
});
But I keep on getting the following error:
Error: Unexpected request: GET http://localhost:3000/api/articles/undefined
Expected GET http://localhost:3000/api/articles/123
at $httpBackend (/Users/gill/Documents/projects/angularjs-test/app/bower_components/angular-mocks/angular-mocks.js:1179)
at sendReq (/Users/gill/Documents/projects/angularjs-test/app/bower_components/angular/angular.js:8181)
at /Users/gill/Documents/projects/angularjs-test/app/bower_components/angular/angular.js:7921
at /Users/gill/Documents/projects/angularjs-test/app/bower_components/angular/angular.js:11319
at /Users/gill/Documents/projects/angularjs-test/app/bower_components/angular/angular.js:11405
at /Users/gill/Documents/projects/angularjs-test/app/bower_components/angular/angular.js:12412
at /Users/gill/Documents/projects/angularjs-test/app/bower_components/angular/angular.js:12224
at /Users/gill/Documents/projects/angularjs-test/app/bower_components/angular-mocks/angular-mocks.js:1438
at /Users/gill/Documents/projects/angularjs-test/test/spec/controllers/article.js:77
Error: Unsatisfied requests: GET http://localhost:3000/api/articles/123
at /Users/gill/Documents/projects/angularjs-test/app/bower_components/angular-mocks/angular-mocks.js:1472
at /Users/gill/Documents/projects/angularjs-test/test/spec/controllers/article.js:65
This is the first time am writing unit tests which I followed along by reading some tutorials. I don't know what am I doing wrong?
Your problem is a simple, but a common one.
When you write your Jasmine / Karma unit tests, creating your controllers are almost automatic using the $controller service. That means, for the most part, you can say from your unit test
$controller('ArticleDetailCtrl')
And AngularJS will figure out its dependent services, inject them and create an instance of the controller for you to unit test.
There is one exception to this:
AngularJS does not know how to inject context specific services like $scope and $routeParams, which change based on the HTML structure and the URL for each instance of the controller.
I notice in your unit test you create the controller as
ArticleDetailCtrl = $controller('ArticleDetailCtrl', { $scope: scope });
So at this point, you tell AngularJS what object to use when the controller asks for $scope as a dependent service. But in your controller, you also inject $routeParams. And based on its articleId you create the URL for the request.
So if you change your controller instantiation code to:
ArticleDetailCtrl = $controller('ArticleDetailCtrl', {
$scope: scope,
$routeParams: articleId: ArticleId
});
That should now create the correct URL (instead of using undefined for articleId, which was the error)
Let me know if that helps.

How to write a Karma test to see if a factory function is being called by a controller in Angular?

I'm learning to use Karma and Jasmine for unit-testing in Angular, and am trying to determine how to properly mock out a factory and test that it is called by a controller. The factory makes a simple http request from the ESPN API. When the controller calls it, it passes the response data to an array. What I have so far is based off of this: Angular unit-test controllers - mocking service inside controller. Unfortunately I just can't seem to get it right.
Here is what my controller and factory look like:
angular.module('TeamApp.services',[])
.factory('espnAPIservice',function($http) {
var espnAPI = {};
espnAPI.getTeams = function() {
return $http({
method: 'GET',
url: 'http://api.espn.com/v1/sports/hockey/nhl/teams?'
})
}
return espnAPI;
});
//Calls the espnAPIservice and stores the retrieved information in an array
angular.module('TeamApp.controllers',[])
.controller('TeamCtrl', ['$scope','espnAPIservice',function($scope,espnAPIservice) {
$scope.teams = [];
espnAPIservice.getTeams().success(function (response) {
$scope.teams = response;
});
}]);
angular.module('TeamApp',['TeamApp.services','TeamApp.controllers']);
Here is my test for it so far:
describe('controller: TeamCtrl', function() {
var $scope, ctrl;
//Inject controller module into the factory that it the controller will call
beforeEach(module('TeamApp.controllers', function($provide) {
var espnAPIservice = {
getTeams: function(){}
};
spyOn(espnAPIservice,'getTeams').andReturn('ESPN'); //change return value
$provide.value('espnAPIservice',espnAPIservice);
}));
//Inject the $controller and $rootScope services
beforeEach(inject(function($rootScope, $controller, espnAPIservice) {
//Create a new scope that is the child of $rootScope
$scope = $rootScope.$new();
//Create the controller
ctrl = $controller('TeamCtrl',{$scope: $scope, espnAPIservice: espnAPIservice});
}));
it('should call the getTeams function', function(){
expect($scope.teams).toBe('ESPN');
});
And here is the error I get when I run the test:
PhantomJS 1.9.7 (Windows 7) controller: TeamCtrl should call the getTeams function FAILED
TypeError: 'undefined' is not a function (evaluating 'espnAPIservice.getTeams().success(function (response) {
$scope.teams = response;
})')
at c:/Users/jquering/Documents/Coding Practice/Angular Practice/nhlStats/app/scripts/teams.js:21
at invoke (c:/Users/jquering/Documents/Coding Practice/Angular Practice/nhlStats/app/lib/angular.js:3762)
at instantiate (c:/Users/jquering/Documents/Coding Practice/Angular Practice/nhlStats/app/lib/angular.js:3773)
at c:/Users/jquering/Documents/Coding Practice/Angular Practice/nhlStats/app/lib/angular.js:6884
at c:/Users/jquering/Documents/Coding Practice/Angular Practice/nhlStats/test/controllers/spec/main.js:18
at invoke (c:/Users/jquering/Documents/Coding Practice/Angular Practice/nhlStats/app/lib/angular.js:3762)
at workFn (c:/Users/jquering/Documents/Coding Practice/Angular Practice/nhlStats/app/lib/angular-mocks.js:2144)
undefined
Expected [ ] to be 'ESPN'.
PhantomJS 1.9.7 (Windows 7): Executed 1 of 1 (1 FAILED) ERROR (0.009 secs / 0.008 secs)
Any help would be much appreciated!
how to properly mock out a factory
beforeEach(module(function ($provide){
$provide.factory('TheSameName', function (){
//return your mock here
});
}));

Resources