Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some style colors ignored #214

Closed
PavelPZ opened this issue Nov 1, 2018 · 2 comments
Closed

Some style colors ignored #214

PavelPZ opened this issue Nov 1, 2018 · 2 comments

Comments

@PavelPZ
Copy link

PavelPZ commented Nov 1, 2018

I am using react-testing-library 5.2.3 with JEST 23.6.0 and REACT 16.7.0-alpha.0.

I have problem with this code...

describe("COLR PROBLEM", () => {
  let comp = render(<div style={{ color: 'lightblue', backgroundColor: 'blue' }} />)
  let { color, backgroundColor } = (comp.container.firstElementChild as HTMLElement).style
  comp = render(<div style={{ color: 'blue', backgroundColor: 'lightblue' }} />)
  let { color: color2, backgroundColor: backgroundColor2 } = (comp.container.firstElementChild as HTMLElement).style
  console.log({ color, backgroundColor, color2,  backgroundColor2 })
})

which logs following:
Object {color: "", backgroundColor: "blue", color2: "blue", backgroundColor2: ""}

It seems that colors other than basic one (with light or dark prefix) are ignored.

Colors is lost during

_reactDom.default.render(ui, container);

at line 51 in node_modules\react-testing-library\dist\index.js

@vitalyso
Copy link
Contributor

vitalyso commented Nov 2, 2018

I've done research for this issue and can say for sure the root of the problem is in the cssstyle module, they allow only limited amount of color aliases.

The simplified dependency chain looks like below (actually it's more complicated):
react-testing-library => jest => jsdom => cssstyle

So if you need more colors to be available, I encourage you to create a PR to the cssstyle repository and wait when all the libraries will make updates. Hope it helped 🙂

@PavelPZ
Copy link
Author

PavelPZ commented Nov 2, 2018

Ok, thanks for hint...

@PavelPZ PavelPZ closed this as completed Nov 2, 2018
wardpeet pushed a commit to gatsbyjs/gatsby that referenced this issue Mar 27, 2019
## Description

Certain CSS styles have been failing to appear in Jest tests due to an outdated JSDom(and some it's dependencies, one being updated with bugfix in Feb 2019). This was causing false positives for `gatsby-image` tests for a while.

Nothing major, just some CSS props weren't appearing in tests when they technically should have been.

## Details

[My PR](#12468) is failing in the CI but was passing tests locally.

I had been running tests on the `gatsby-image` package on it's own, which uses `react-testing-library: ^5.0.0`, and it failed against the snapshot test. Updated snapshots failed when my PR ran on CircleCI. The main repo root yarn.lock file has `react-testing-library: ^5.2.1` locked down(retrieves 5.2.1 instead of 5.9.0, although is a v6 release now). 

Correcting this didn't help for passing the test suite. [`cssstyle: 1.2.0`](jsdom/cssstyle#74) fixes the [problems with certain styles](jsdom/jsdom#1965 (comment)) being [ignored](testing-library/react-testing-library#214. `transitionDelay`, and certain color values for `backgroundColor`, "red" works, but not "lightgray"). That however [needs `jsdom: ^12.0.0`](jsdom/jsdom@ed11465#diff-b9cfc7f2cdf78a7f4b91a753d10865a2), but [Jest refuses to update as support for Node <8 is dropped](jestjs/jest#8016 (comment))..

I've added a workaround until Jest supports a newer major version of JSDom. Using [`jest-environment-jsdom-fourteen`](https://github.com/ianschmitz/jest-environment-jsdom-fourteen) is the [advised approach](jestjs/jest#7122 (comment)) for the meantime, it'll only impact users running Jest test suite on Node 6, that should be fine for Gatsby? (Node 6 CI test seems to pass)

Only `gatsby-image` tests needed updates. [Node 6 will be EoL in May](https://github.com/nodejs/Release#release-schedule), no idea when Jest will bump JSDom from then, but we could wait a few months if you rather avoid the workaround?

## Related Issues

#12468 (Spotted it while working on this)
lucbpz pushed a commit to lucbpz/react-testing-library that referenced this issue Jul 26, 2020
* docs: update README.md

* docs: update .all-contributorsrc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants