Hi:
As you can see by looking at this controller:
https://github.com/neosavvy/dropwizard-js-user-management/blob/master/commons-user-client/src/main/resources/angular/js/controller1.0.js I am using $resource to interact with my service. Now I am working on unit testing this bad-boy. I noticed that i consistently get this error when trying to instantiate the unit test and I have now learned that this is because angular-mocks.js doesn't include a mock version of $resource. If that is the case is it a good idea to avoid $resource and use instead $http for all REST-ful service calls? I just want to make sure I am using the best approach for the future before I get too far off track.
If you can pass me an example of a CRUD-style controller with a unit test I'd appreciate that as well to see if I am doing this all right.
Error is below followed by some sample code I am attempting to use for the unit test.
myController function UserController.should have a hello string with a value of "hello" failed (4.00 ms): Error: Error: Unknown provider: $resourceProvider <- $resource
Error: Expected undefined to be 'hello'.
Error: Unknown provider: $resourceProvider <- $resource
at Error (unknown source)
at _/main/resources/admin/js/lib/angular.js:2627:23
at Object.getService [as get] (_/main/resources/admin/js/lib/angular.js:2755:53)
at _/main/resources/admin/js/lib/angular.js:2632:53
at getService (_/main/resources/admin/js/lib/angular.js:2755:53)
at invoke (_/main/resources/admin/js/lib/angular.js:2773:31)
at Object.instantiate (_/main/resources/admin/js/lib/angular.js:2805:33)
at _/main/resources/admin/js/lib/angular.js:4619:34
at [object Object].<anonymous> (unit/controllersSpec.js:19:30)
at Object.invoke (_/main/resources/admin/js/lib/angular.js:2795:40)
Error: Declaration Location
at lib/angular/angular-mocks.js:1696:21
at [object Object].<anonymous> (unit/controllersSpec.js:13:20)
at [object Object].<anonymous> (unit/controllersSpec.js:9:5)
Error: Expected undefined to be 'hello'.
at [object Object].<anonymous> (unit/controllersSpec.js:23:33)
Unit test:
'use strict';
/* jasmine specs for controllers go here */
describe('myController function', function() {
describe('UserController', function(){
var userController;
var scope, userController, $httpBackend;
beforeEach(inject(function($rootScope, $controller, _$httpBackend_) {
scope = $rootScope.$new();
$httpBackend = _$httpBackend_;
$httpBackend.expectGET('phones/phones.json').
respond([{name: 'Nexus S'}, {name: 'Motorola DROID'}]);
userController = $controller(UserController, {$scope: scope});
}));
it('should have a hello string with a value of "hello"', function() {
expect(scope.hello).toBe('hello');
});
});
});