2013-03-04 4 views
3

컨트롤러를 감싸고있는 다음 사양이 있습니다. 나는 다음과 같은 재스민 사양있어 : SomeService는 다음과 같이 정의된다ngMock이 요청을 인식하지 못합니다.

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'] 

은 다음과 같습니다 :

MyApp.Service.SomeService = (resource) -> 
    @someResource = resource '/api/foos/:ID', {}, 
    fetch: 
    method: 'GET' 

    @ 

MyApp.myModule.service 'SomeService', ['$resource', MyApp.Service.SomeService] 

이 설정은에 작동하도록 나타나는

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() 

다음 컨트롤러 감싸 요청을 올바르게 실행하고 (레일스) 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']

답변

4

당신이 요청하기 전에 가야 응답을 스텁이 줄 :

@httpBackend.whenGET().respond(200, {"someStrings": ["foo", "bar"], otherStrings: ["bar", "goo"]}) 
관련 문제