柏树抛出未捕获的TypeError:非法调用似乎是误报 [英] cypress throwing Uncaught TypeError: Illegal invocation appears to be false positive

查看:102
本文介绍了柏树抛出未捕获的TypeError:非法调用似乎是误报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在rails(5.1.6)项目中,当Cypress(3.1.0)测试套件单击注销链接时,将引发未捕获的TypeError:非法调用错误。输出继续说明此错误源于您的应用程序代码,而不是赛普拉斯。

In a rails (5.1.6) project, when a Cypress (3.1.0) test suite clicks a Logout link, an "Uncaught TypeError: Illegal invocation" error is thrown. The output goes on to explain that "This error originated from your application code, not from Cypress."

单击时跟踪我的本地服务器日志并执行相同的操作在chrome javascript控制台中,我找不到任何引发的错误。当应用程序在开发模式下运行时,单击注销按钮不会产生任何错误。作为进一步的测试措施,我可以将环境设置为测试模式,并与注销按钮进行交互,而不会发生意外。

Tracking my local server logs when the click takes place and doing the same in the chrome javascript console, I can find no errors of any kind being thrown. Clicking the Logout button when the app runs in development mode produces no error. As a further test measure, I can set up my environment in "test" mode and interact with the Logout button without incident.

我已在测试中添加了此位克服错误:

I've added this bit to my tests to get past the error:

Cypress.on('uncaught:exception', function (err, runnable) {
    //debugger;
    return false;
});

链接栏生成如下:

< a class = btn btn-outline-light my-2 my-sm-0 rel = nofollow data-method = delete href = / logout> Log out< / a>

我很讨厌声称这是赛普拉斯的一个bug,但我的代码似乎直截了当赛普拉斯或其他方式单击此链接时,我可以确定不会引发任何错误。

I'm loathe to claim this is a bug in Cypress, but my code seems straight forward and as far as I can tell is not throwing any errors when this link is clicked by Cypress or otherwise.

我正在使用Devise进行会话管理。

I'm using Devise for session management.

所以我有两个问题:


  1. 这可能是赛普拉斯中的错误吗?

  2. 当抛出Cypress.on uncaught:exception语句时,是否有一种方法可以捕获单击哪个特定按钮的情况,这样我就不会错过需要捕获实际错误的情况?


推荐答案

我不确定您是否解决了此问题。我发现了这个问题,并设法找到了解决方案。在您的示例中,您使用 link_to 生成锚点 a 标记,但这是 delete 请求。通常,它们用于 get 请求。一些Rails的魔法使我们能够做到这一点。为什么赛普拉斯确实对此有问题,我不确定,但是如果您还原帖子输入删除请求到 form_for 应该可以解决您的问题!希望这会有所帮助!

I'm not sure if you ever resolved this issue. I found this issue and managed to find a solution. In your example you are using a link_to to generate an anchor a tag but it's a delete request. Conventionally, they are for get requests. Some Rails magic allows us to do this. Why Cypress exactly has a problem with this I'm not sure but if you revert your post, put, delete requests to form_for that should solve your problem! Hope this helps!

这篇关于柏树抛出未捕获的TypeError:非法调用似乎是误报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆