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.

cy.log now returns null in v10.5, used to be undefined

See original GitHub issue

Current behavior

cy.log used to return undefined, so it could be inserted into the command chain without changing the subject

...
  .then(cy.log)
  ...

Now cy.log returns null, changing the subject

Desired behavior

cy.log should still return undefined

Test code to reproduce

Repo and branch https://github.com/bahmutov/cypress-test-tiny/tree/cy-log-bug

describe('cy.log', () => {
  it('works', () => {
    cy.wrap(42).should('equal', 42)
  })

  it('does not work', () => {
    // not working in Cypress v10.6.0
    // not working in v10.5.0
    // worked in v10.4.0
    // fails with "null" not equal 42
    cy.wrap(42).then(cy.log).should('equal', 42)
  })
})

Cypress Version

10.5.0

Node version

16

Operating System

mac

Debug Logs

No response

Other

No response

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
bahmutovcommented, Aug 17, 2022

Ughh, the change makes no sense. Sure, the docs could be saying (an incorrect) thing for 6 years, yet it was not an issue and allowed to quickly print a value inside a long chain. The advice to close the chain with cy.log does not really help.

The solution is to write a big callback and wrap the value - no, just no. Instead, I would suggest

  • returning undefined from cy.log. I don’t see any reason to change the subject in cy.log, we already have plenty of problems with should('have.attr') and similar assertions that do unexpectedly change the subject
  • extend cy.log to intelligently stringify an object when passed in (so it does not collapse it into [object Object])

just my two million cents

1reaction
mike-plummercommented, Aug 18, 2022

@bahmutov The conclusion we’ve come to internally is that this was not an intentional change, and it is just a coincidence that the behavior actually now matches our documentation. So, this isn’t strictly a bug but rather a feature request to change the documented behavior back to the previous implementation. That said, it’s a good one - the use case you’ve lined out feels very useful. We’ll send this on to the team to do analysis and prioritize

(internal convo ref)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why cy.log prints null or undefined - YouTube
Sometimes we call cy. log (variable) yet it always prints null or undefined. In this video, I explain why this happens and how...
Read more >
Changelog - Cypress Documentation
Cypress now throws an error if any Cypress commands are invoked from inside a .should() callback. This previously resulted in unusual and undefined...
Read more >
Why cy.log Prints Nothing - Gleb Bahmutov
log command prints null or undefined even if the variable is set by the Cypress test. This is a very common question and...
Read more >
Fix List for DB2 Version 10.5 for Linux, UNIX and Windows - IBM
APAR Sev. Abstract IJ11422 2 MEMORY LEAK IN DB2TOP WHEN VIEWING DYNAMIC SQL IT28111 2 QUERIES USING HASH JOINS MAY HANG INTERMITTENTLY IT29647 2 SIG#11 RUNNING...
Read more >
Best Practices Upgrade to DB2 LUW 10.5 with BLU Acceleration
If wish to downgrade instance back to V10.5 FP1 code base: ... Rolling forward of logs from a previous level is not possible....
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