Skip to content

Commit fef46cf

Browse files
committed
Add: tests for toHaveSomeStyles
1 parent 5bedb23 commit fef46cf

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,33 @@ describe("[Unit] ElementAssertion.test.ts", () => {
351351
const divTest = getByTestId("test-div");
352352
const test = new ElementAssertion(divTest);
353353

354-
expect(test.toHaveSomeStyle({ color: "red", display: "block" })).toBeEqual(test);
354+
expect(test.toHaveSomeStyle({ color: "blue", display: "flex" })).toBeEqual(test);
355+
356+
expect(() => test.not.toHaveSomeStyle({ color: "blue" }))
357+
.toThrowError(AssertionError)
358+
// eslint-disable-next-line max-len
359+
.toHaveMessage("Expected the element NOT to match some of the following styles:\n{\n \"color\": \"rgb(0, 0, 255)\"\n}");
360+
});
361+
});
362+
363+
context("when the element does not contain any of the expected styles", () => {
364+
it("throws an assertion error", () => {
365+
const { getByTestId } = render(
366+
<div
367+
className="foo bar test"
368+
style={{ border: "1px solid black", color: "blue", display: "block" }}
369+
data-testid="test-div"
370+
/>,
371+
);
372+
const divTest = getByTestId("test-div");
373+
const test = new ElementAssertion(divTest);
374+
375+
expect(() => test.toHaveSomeStyle({ color: "red", display: "flex" }))
376+
.toThrowError(AssertionError)
377+
// eslint-disable-next-line max-len
378+
.toHaveMessage("Expected the element to match some of the following styles:\n{\n \"color\": \"rgb(255, 0, 0)\",\n \"display\": \"flex\"\n}");
379+
380+
expect(test.not.toHaveSomeStyle({ border: "1px solid blue", color: "red", display: "flex" })).toBeEqual(test);
355381
});
356382
});
357383
});

0 commit comments

Comments
 (0)