question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cypress 3.0.0 doesn't always trigger onclick when calling .check() on radio buttons

See original GitHub issue

Is this a Feature or Bug?

Bug

Current behavior:

Calling .check() on a radio button will visually check it but the onclick code doesn’t run. This was not the case with 2.1.0

Desired behavior:

Calling .check() on a radio button should trigger the onclick handler.

Steps to reproduce:

I’m not 100% sure what the cause is. I created a simple HTML file to test this on and it worked as expected, so maybe Cypress 3.0 handles a more complicated DOM differently. I can’t post the actual HTML I’m testing on since it is a company product.

Versions

Cypress 3.0.0, Windows

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
bkjohnsoncommented, Jun 2, 2018

I have something that shows the problem. I’m trying to test a site and the inputs have an onclick that is generated in the form onclick="javascript:setTimeout('postbackCall(\'id\')',0)". It looks like Cypress 3.0.0 is having trouble with the code parameter in setTimeout.

Here is an example that shows the issue:

//javascript.js

function postbackCall(foo) {
  console.log(foo)
}
<!--test.html-->
<body>
  <script src="javascript.js"></script>
  <input type="radio" id="click1" onclick="javascript:console.log('foo')">Click me</input>
  <input type="radio" id="click2" onclick="javascript:setTimeout('postbackCall(\'bar\')', 0)">No log</input>
</body>
//spec.js 

context('Testing', () => {
  it('Checks a radio button', () => {
    cy.visit('test.html')
    cy.get('#click1').check()
    cy.get('#click2').check()
  })
})

In Cypress 2.1.0 the console log will show foo as well as bar, but in 3.0.0 foo is displayed and then Cypress errors out on the call to the second .check(), saying fn.apply is not a function. I can stop the error from ending the test by catching the uncaught exception, but this still prevents the postback from happening which is necessary for the app to function.

1reaction
brian-manncommented, Sep 6, 2018

@jbinto yah the issues described above definitely don’t have anything to do with the checkbox not checking - so we’ll need a reproducible example to figure this out.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cypress does not always executes click on element
When that script takes a long time to execute it allows Cypress to click the button before the OnClick event is there. See:...
Read more >
fix this problem, or use {force: true} to disable error checking.
Before I log a detailed issue, can someone tell me if the scrollIntoView() function supposed to scroll elements or does it only scroll...
Read more >
check - Cypress Documentation
Check checkbox(es) or radio(s). It is unsafe to chain further commands that rely on the subject after .check(). This element must be an...
Read more >
onClick event for radio button - Topic - Focal Point Forums
How do you add an onClick event handler for a radio button control? The "control" is a set of three radio buttons. In...
Read more >
react onclick triggered on render Code Example - Code Grepper
Why is my onClick being called on render react? ... react why onclick property function trigger without click ... <button type="button" onClick={this.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found