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:
- Is it possible this is a bug in Cypress?
- 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?
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 anchora
tag but it's adelete
request. Conventionally, they are forget
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 yourpost
,put
,delete
requests toform_for
that should solve your problem! Hope this helps!