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

toHaveStyle false positive with 8 digit hex #425

Closed
cassiourugit opened this issue Jan 5, 2022 · 3 comments
Closed

toHaveStyle false positive with 8 digit hex #425

cassiourugit opened this issue Jan 5, 2022 · 3 comments

Comments

@cassiourugit
Copy link

Hi, me and @matheusliraofficial are having some issues when using toHaveStyle to assert colors with opacity. The tests are giving a false positive

Here's a sample of my problem:

If I do it like this:
expect(menuItem).toHaveStyle({ backgroundColor: '#ffffff' });

The test fails like expected, because the white I'm validating has 16% opacity

If I do it like this:
expect(menuItem).toHaveStyle({ backgroundColor: '#ffffff29' });

The test passes, but it's a false positive, no matter the number it put on the opacity, it always passes

If I try with RGBA instead of hex:
expect(menuItem).toHaveStyle({ backgroundColor: 'rgba(255, 255, 255, 0.16)' });

The test always fails, even with the correct color and opacity

Someone knows how to make opacity assertions work with toHaveStyle?

@gnapse
Copy link
Member

gnapse commented Jan 5, 2022

This is most likely an issue with jsdom's lack of proper support for all CSS features in its getComputedStyle functionality. jest-dom relies on this functionality. For context, see #350, #392, #322 and #280 (and there may be more).

I honestly do not have much time to fully dig into these issues. But I'm more than happy to help if someone digs enough to find more concrete actional steps to be taken.

@cassiourugit
Copy link
Author

What fixed this to me was changing the
jest-environment-jsdom-fourteen
to
"jest-environment-jsdom": "^26.6.2",

@gnapse
Copy link
Member

gnapse commented Feb 24, 2022

That's great to know, @cassiourugit!

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