0

The problem

I'm trying to test the border is red if the component is in error state, but it's failing in local machine, but not in codesandbox

What I have tried:

Code Component with error state set to true

import React from "react";
import "./styles.css";
import FormControl from "@material-ui/core/FormControl";
import FormHelperText from "@material-ui/core/FormHelperText";
import Select from "@material-ui/core/Select";

export const SelectInput = () => {
  return (
    <FormControl error={true} variant="outlined">
      <Select />
      <FormHelperText> test </FormHelperText>
    </FormControl>
  );
};

Testing

import { render, screen, waitFor } from "@testing-library/react";
import "@testing-library/jest-dom/extend-expect";
import { SelectInput } from "../App";
test("test form control error state", async () => {
  render(<SelectInput />);

  const fieldSet = screen.getByRole("group", { hidden: true });
  const helperText = screen.getByText("test");
  await waitFor(() => expect(fieldSet).toBeInTheDocument());

  expect(helperText).toHaveStyle(`color: #f44336;`);
  expect(fieldSet).toHaveStyle(`border-color: #f44336;`);
});

codesanbox link https://codesandbox.io/s/rtl-mui-select-test-style-border-tekgl?file=/src/test/select.test.js:0-549

EDIT 2 Local machine error logs:

  ● should accept error string props

    expect(element).toHaveStyle()

    - Expected

    - border-color: #f44336;
    + border-color: rgba(0, 0, 0, 0.23);

    >  97 |   expect(fieldSet).toHaveStyle(`border-color: #f44336;`)

Any leads will be much appreciated. Thank you

Orville
  • 518
  • 7
  • 17
  • what's the error you receive in local env ? – aquinq Jun 04 '20 at 18:09
  • Hi @aquinq thanks for the response, please see my edit :) – Orville Jun 05 '20 at 12:11
  • Thanks, the error is related to `should accept error string props ` test, but in the codesanbox the test is `test form control error state` ? – aquinq Jun 05 '20 at 13:20
  • the test title may differ but the test are the same. One more thing that confuses me is the `helperText` is passing the test and having the `border-color: #f44336;` – Orville Jun 05 '20 at 13:44

0 Answers0