Skip to content

[jest-dom/prefer-to-have-style] doesn't report when using .toBe(variable) #384

Open
@StyleShit

Description

@StyleShit
  • eslint-plugin-jest-dom version: 5.5.0
  • node version: 18.20.3
  • npm version: 10.2.3

Relevant code or config:

// eslintrc.js
{
	// ...
	rules: {
		'jest-dom/prefer-to-have-style': 'error',
	}
}
// component.test.js

expect(node.style.color).toBe('red'); // Works

const red = 'red';
expect(node.style.color).toBe(red); // Doesn't work

What happened:

I'm referencing a variable in the toX() methods, but the rule doesn't report.
I would've expected it to report. Is it intentional? Didn't find other issues mentioning this, but the selectors in the code don't seem to handle it.

Reproduction repository:

StackBlitz

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions