Cypress: Select values lost in snapshots

Created on 12 Jun 2019  路  7Comments  路  Source: cypress-io/cypress

Current behavior:

When viewing a snapshot the values of <select> elements are lost. <input> element preserve their value fine, however.

This is minor, but it's happening in my percy tests too and I guess it's caused by the same thing.

Desired behavior:

<select> elements should appear in snapshots as they appeared at the time.

Steps to reproduce: (app code and test code)

Repo and steps to replicate in readme: https://github.com/callumacrae/cypress-select-value-issue

Versions

Cypress 3.3.1

ready for work unexpected behavior

Most helpful comment

can lead to wasted time trying to figure out why the selected values are wrong (which is what happened to me).

That's what happened to me, too!

All 7 comments

Thanks for opening an issue. This is a known issue, although I am not sure there has been an issue opened for it previously - so we'll leave this issue open to track this.

A cursory search doesn't reveal similar issues. And actually, the issue is minor only when you know about it. I thought there was something with my tests, took me a while to confirm that everything's fine. Here's my report just in case :)

Okay, I see, the issue is with cloning the DOM here. It all comes down to the fact that Node.cloneNode() doesn't clone select's properties. It's so in the spec (won't fix), in chrome and ff (won't fix), and jquery (won't fix). The last hope is cypress :)

Possible workaround:

$origBody = $$('body')
$body = $origBody.clone()
$selects = $body.find('select')
$origBody.find('select').each(
    (i, os) => $selects[i].value = os.value
)

A fiddle: https://jsfiddle.net/xyuri/d2h6yzen/

@jennifer-shehane Could this make it resolved faster?

And actually, the issue is minor only when you know about it.

I disagree that this is a minor issue; being able to see the state of the select options in your app is valuable.

However, for users who don't know that this is a bug in cypress and not a bug in their app, it's even worse, and can lead to wasted time trying to figure out why the selected values are wrong (which is what happened to me).

can lead to wasted time trying to figure out why the selected values are wrong (which is what happened to me).

That's what happened to me, too!

Running into this more than a year later. This is an issue when using visual testing solutions such as Percy or Happo. Is it also a wontfix on cypress's end?

@matthieu-foucault This is not a 'wontfix', it is labeled as 'ready for work' and an open issue. It is just not prioritized currently.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

verheyenkoen picture verheyenkoen  路  3Comments

rbung picture rbung  路  3Comments

carloscheddar picture carloscheddar  路  3Comments

igorpavlov picture igorpavlov  路  3Comments

jennifer-shehane picture jennifer-shehane  路  3Comments