0

Consider in CSS,

.content
{
    width:500px;
    box-sizing: border-box;
}

I have added this css class inside react component as following

const Banner = () => {
   return (<div className="content">This is message content</div>);
} 

How to write jest and enzyme test cases to ensure the 'box-sizing' with 'border-box' applied properly?

Notes: I can write the test case to ensure the ".content" class added to this element. But exactly, i need to write test case to ensure the value in 'box-sizing'.

2 Answers 2

1

I am not sure how to fix your issue, but keep in mind your test will not cover

* {
  box-sizing: border-box;
}

if you will defined somewhere alse.

From my perspective, it does not make sense to test styles, because we can not guaranty from the test perspective that element will look like we want to. So still you will need to open the browser and check your element works properly, but you are writing tests to avoid it.

Sign up to request clarification or add additional context in comments.

Comments

0

By adding this code to Banner.test.js file, it'll check if className called content have inline style property for box-sizing and is it equal to border-box or not. But it'll test only inline styles.

const banner = shallow(<Banner/>);
it("render propperely", () => {
expect(banner).toMatchSnapshot();
expect(banner.find(".content")
.get(0).props.style).toHaveProperty("box-sizing", "border-box");
  });

2 Comments

Please update your answer to provide context in plain english
Can you explain a little bit how this answer will solve the problem, instead of posting code-only answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.