cypress throwing Uncaught TypeError: Illegal invocation appears to be false positive

不问归期 提交于 2019-12-24 09:13:46

问题


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."

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;
});

The link rails generates looks like this:

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

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.

I'm using Devise for session management.

So I have two questions:

  1. Is it possible this is a bug in Cypress?
  2. Is there a way to trap which specific button was clicked when the Cypress.on uncaught:exception statement is thrown so that I don't miss cases where an actual error needs to be caught?

回答1:


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!



来源:https://stackoverflow.com/questions/52634612/cypress-throwing-uncaught-typeerror-illegal-invocation-appears-to-be-false-posi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!