AngularJS $httpBackend 'expect' 无法正常工作
AngularJS $httpBackend 'expect' does not work correctly
所有!
使用AngularJS、Rails、茉莉花
当我在测试中使用来自 $httpBackend 服务的 expect
时,
根据 official docs 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()
,但是,当我 运行 测试时,引发异常:
Error: Unexpected request: GET acts/1?id=1&month=09%2F2015
Expected GET acts/1
我试过插入哈希、字符串等数据,json,结果是一样的...
只有当我将 url 与数据一起使用时它才有效:
@http.expect('GET', 'acts/1?id=1&month=09%2F2015').respond(200)
所以它不能正常工作
也许有人会说,我如何向 expect
方法插入数据???
谢谢!
我认为 expect
中的 data
参数只应在您发送除 URL 之外的负载时使用,例如当您致电 POST
或 PATCH
.
对于 GET 请求,您应该在 URL 中包含您的编码参数,就像您写的那样:
@http.expect('GET', 'acts/1?id=1&month=09%2F2015').respond(200)
所有!
使用AngularJS、Rails、茉莉花
当我在测试中使用来自 $httpBackend 服务的 expect
时,
根据 official docs 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()
,但是,当我 运行 测试时,引发异常:
Error: Unexpected request: GET acts/1?id=1&month=09%2F2015
Expected GET acts/1
我试过插入哈希、字符串等数据,json,结果是一样的...
只有当我将 url 与数据一起使用时它才有效:
@http.expect('GET', 'acts/1?id=1&month=09%2F2015').respond(200)
所以它不能正常工作
也许有人会说,我如何向 expect
方法插入数据???
谢谢!
我认为 expect
中的 data
参数只应在您发送除 URL 之外的负载时使用,例如当您致电 POST
或 PATCH
.
对于 GET 请求,您应该在 URL 中包含您的编码参数,就像您写的那样:
@http.expect('GET', 'acts/1?id=1&month=09%2F2015').respond(200)