Skip to content

toHaveStyle() doesn't behave as expected #281

Closed
@moroshko

Description

@moroshko

The following test fails with:

expect(element).toHaveStyle()

- Expected

- paddingLeft: ;

  12 |     />
  13 |   );
> 15 |   expect(screen.getByPlaceholderText("example")).toHaveStyle({
  16 |     paddingLeft: 4
  17 |   });
  18 | });
import React from "react";
import "@testing-library/jest-dom/extend-expect";
import { render, screen } from "@testing-library/react";

test("failing test", () => {
  render(
    <input
      placeholder="example"
      style={{
        paddingLeft: 4
      }}
    />
  );

  expect(screen.getByPlaceholderText("example")).toHaveStyle({
    paddingLeft: 4
  });
});

Am I using toHaveStyle() the wrong way, or is this a bug?

The error message is also pretty confusing 😕

CodeSandbox

  • @testing-library/jest-dom version: 5.11.1
  • node version: 12.6.0
  • npm version: 6.14.6
  • react-testing-library version: 10.4.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is neededreleased

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions