所有!
使用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
方法???
谢谢!
答案 0 :(得分:1)
我认为data
中的expect
参数只应在您发送除网址之外的有效负载时使用,例如当您致电POST
或PATCH
。
对于GET请求,您应该在URL中包含编码参数,就像您写的那样:
@http.expect('GET', 'acts/1?id=1&month=09%2F2015').respond(200)