AngularJS $ httpBackend'期待'无效

时间:2015-09-18 13:00:28

标签: angularjs jasmine

所有!

使用AngularJS,Rails,Jasmine

当我在测试中使用来自 $ httpBackend 服务的expect时, 根据{{​​3}} expect(method, url, [data], [headers]);

在我的测试中:

describe 'when something', ->
  it 'response success', ->
    @http.expect('GET', 'acts/1', {month: '09/2015'}).respond(200)
    @scope.createAct()
    @http.flush()

,但是,当我运行测试时,提高exeption:

Error: Unexpected request: GET acts/1?id=1&month=09%2F2015
Expected GET acts/1

我已尝试插入数据,如hash,string,json,结果相同......

仅当我将url与数据一起使用时,它才有效:

@http.expect('GET', 'acts/1?id=1&month=09%2F2015').respond(200)

所以它正常工作

也许有人可以说,我如何将数据插入expect方法???

谢谢!

1 个答案:

答案 0 :(得分:1)

我认为data中的expect参数只应在您发送除网址之外的有效负载时使用,例如当您致电POSTPATCH

对于GET请求,您应该在URL中包含编码参数,就像您写的那样:

@http.expect('GET', 'acts/1?id=1&month=09%2F2015').respond(200)