eslint-plugin-jest-dom icon indicating copy to clipboard operation
eslint-plugin-jest-dom copied to clipboard

[prefer-to-have-style] error when attempting to fix with computed access of `el.style`

Open G-Rath opened this issue 2 years ago • 0 comments

expect(imageElement.style[computed]).toBe(`inset 0px 0px 0px 400px ${c}`)

This errors:

A fatal parsing error occurred in autofix.
    Error: Parsing error: Unexpected token :
    Autofix output:
    expect(imageElement).toHaveStyle(: inset 0px 0px 0px 400px ${c}`)

We should not provide a fixer for this case, because we can't determine if the matcher value is meant to be a property or a value so can't correctly fix it.

e.g.

expect(el.style[computed]).toEqual('padding');

// should become
expect(el.style[computed]).toHaveStyle({ padding: expect.anything() });

// but instead becomes
expect(el.style[computed]).toHaveStyle('padding');
expect(el.style[computed]).toEqual('padding');

// should become
expect(el.style[computed]).toHaveStyle({ [computed]: '5px' });
expect(el.style[computed]).toHaveStyle({ padding: expect.anything() });

// but instead becomes
expect(el.style[computed]).toHaveStyle({ '5px': expect.anything() });

(because of #264)

G-Rath avatar May 20 '22 02:05 G-Rath