Skip to content

Commit 7b0938b

Browse files
committed
Add: test for when styles are the same and the opposite case
1 parent 6efcdef commit 7b0938b

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

packages/dom/test/unit/lib/ElementAssertion.test.tsx

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,16 +266,41 @@ describe("[Unit] ElementAssertion.test.ts", () => {
266266
});
267267

268268
describe(".toHaveStyle", () => {
269+
context("when the element has the expected style when passed as string", () => {
270+
it("returns the assertion instance when the styles are the same", () => {
271+
const { getByTestId } = render(<div className="foo bar test" style={{ display: "flex", color: "red", border: "1px solid black" }} data-testid="test-div" />);
272+
const divTest = getByTestId("test-div");
273+
const test = new ElementAssertion(divTest);
274+
275+
expect(test.toHaveStyle("color: red; display: flex; border: 1px solid black")).toBeEqual(test);
276+
277+
});
278+
it("fails the assertion when the styles are not the same", () => {
279+
const { getByTestId } = render(<div className="foo bar test" style={{ display: "flex", color: "red" }} data-testid="test-div" />);
280+
const divTest = getByTestId("test-div");
281+
const test = new ElementAssertion(divTest);
282+
283+
expect(test.toHaveStyle("color: red; display: flex; border: 1px solid black;")).toBeEqual(test);
284+
285+
});
269286
context("when the element has the expected style when passed as object", () => {
270-
it("returns the assertion instance when it receives an object", () => {
287+
it("returns the assertion instance when the styles are the same", () => {
288+
const { getByTestId } = render(<div className="foo bar test" style={{ display: "flex", color: "red", border: "1px solid black" }} data-testid="test-div" />);
289+
const divTest = getByTestId("test-div");
290+
const test = new ElementAssertion(divTest);
291+
292+
expect(test.toHaveStyle({color: "red", display: "flex", border: "1px solid black"})).toBeEqual(test);
293+
294+
});
295+
it("fails the assertion when the styles are not the same", () => {
271296
const { getByTestId } = render(<div className="foo bar test" style={{ display: "flex", color: "red" }} data-testid="test-div" />);
272297
const divTest = getByTestId("test-div");
273298
const test = new ElementAssertion(divTest);
274299

275-
expect(test.toHaveStyle("display: flex; color: red")).toBeEqual(test);
300+
expect(test.toHaveStyle({color: "red", display: "flex", border: "1px solid black"})).toBeEqual(test);
276301

277302
});
278303
});
279304
})
280-
305+
})
281306
})

0 commit comments

Comments
 (0)