Javascript 与sinon和jasmine一起提交的测试表行动

Javascript 与sinon和jasmine一起提交的测试表行动,javascript,coffeescript,jasmine,sinon,Javascript,Coffeescript,Jasmine,Sinon,我尝试验证在单击submit按钮时是否执行了正确的表单操作。我使用Chrome中的Karma(以前是testacular)运行测试,并使用sinon创建一个假服务器来捕获POST请求。看起来它没有被捕获 形式 伪服务器从未捕获该请求(但类似的代码适用于ajax启动的请求)。但是,运行测试套件的chrome浏览器中出现了一个错误 Failed to load resource: the server responded with a status of 404 (Not Found) http:/

我尝试验证在单击submit按钮时是否执行了正确的表单操作。我使用Chrome中的Karma(以前是testacular)运行测试,并使用
sinon
创建一个假服务器来捕获POST请求。看起来它没有被捕获

形式

伪服务器从未捕获该请求(但类似的代码适用于ajax启动的请求)。但是,运行测试套件的chrome浏览器中出现了一个错误

Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:9876/authenticate_open_id
,所以看起来好像已经完成了一些请求,但假服务器无法捕获它


这无法工作,因为伪服务器只适用于ajax请求。假服务器所做的唯一事情就是模拟XmlHttpRequest对象并调用传递的成功/错误函数。因此,在您的情况下,单击该按钮将在页面重新加载时使用新的帖子url结束

谢谢。这是有道理的。我猜这种形式的行为是不可测试的。
server = sinon.fakeServer.create()
server.autoRespond = true
server.respondWith 'POST', '/authenticate_open_id', [302, {}, '']

view.$el.find('#signup_with_google').click()
waitsFor ->
    server.requests.length > 0
, 'server has not been called', 100                    
runs ->
    console.log 'server', server.requests
Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:9876/authenticate_open_id