我有以下规格缠绕在一个控制器。我有以下茉莉花规格:ngMock无法识别请求
describe 'MyApp.Controller.SomeController', ->
beforeEach module('mymodule')
beforeEach inject ($rootScope , $httpBackend, $controller, SomeService) ->
@scope = $rootScope.$new()
@httpBackend = $httpBackend
someService = SomeService
@someResource = someService.someResource
$controller 'MyApp.Controller.SomeController', $scope: @scope
describe "#fetchMethod", ->
describe "given an object", ->
beforeEach ->
@id = 17
@scope.fetchMethod(@id)
it "sets due to true", ->
@httpBackend.whenGET().respond(200, {"someStrings": ["foo", "bar"], otherStrings: ["bar", "goo"]})
expect(@scope.someStrings).toBeDefined()
expect(@scope.otherStrings).toBeDefined()
缠以下控制器:
MyApp.Controller.SomeController = (scope, someService) ->
scope.fetchMethod = (ID)->
someService.someResource.fetch
Id: artID
,(response) ->
scope.someStrings = response['someStrings']
scope.otherStrings = response['otherStrings']
scope.someStringsExist = true if scope.someStrings
MyApp.Controller.SomeController.$inject = ['$scope', 'SomeService']
凡SomeService定义如下:
MyApp.Service.SomeService = (resource) ->
@someResource = resource '/api/foos/:ID', {},
fetch:
method: 'GET'
@
MyApp.myModule.service 'SomeService', ['$resource', MyApp.Service.SomeService]
这种设置似乎在功能上网站,正确执行请求并从(rails)api端点返回值。
然而,当茉莉规范是运行失败:
Error: Unexpected request: GET /api/foos/17 No more request expected in http://localhost:3000/assets/helpers/angular-mocks.js?body=1 (line 889)
我缺少什么?为什么httpBackend无法识别GET请求?
scope.initialize =(artifactId的,artifactType) - > scope.artifactId = artifactId的 scope.artifactType = artifactType scope.currentVersionExists =假 scope.attachmentFetcher(scope.artifactId)
MyApp.Controller。 。SomeController $注入= '$范围', 'SomeService']