I have the following code:
Controller
angular.module('myApp').controller 'dashboardController', (User) ->
User.find('current').then (data) =>
@currentUser = data
User factory
angular.module('myApp').factory 'User', ($resource) ->
$resource = $resource '/api/v1/users/:id'
@find = (id) ->
$resource.get(id: id).$promise
return this
Controller test
describe 'dashboardController', ->
beforeEach module 'myApp'
beforeEach inject ($controller, User, $rootScope, $q) ->
@dashboardController = $controller 'dashboardController'
@User = User
@$scope = $rootScope
@$q = $q
afterEach ->
@dashboardController = {}
@User = {}
@$scope = {}
@$q = {}
beforeEach ->
@deferredSuccess = @$q.defer()
@deferredSuccess.resolve({foo: 'bar'})
spyOn(@User, 'find').and.returnValue(@deferredSuccess.promise)
it 'should call User.find()', ->
@$scope.$apply()
Test failure message...
Error: Unexpected request: GET /api/v1/users/current
No more request expected
at $httpBackend (/Users/nathan/dev/Swift/admin/bower_components/angular-mocks/angular-mocks.js:1227)
Aucun commentaire:
Enregistrer un commentaire