Skip to content

Commit 2fc9de4

Browse files
committed
Fix: new format for messages and no string cases
1 parent 33320b6 commit 2fc9de4

File tree

1 file changed

+37
-47
lines changed

1 file changed

+37
-47
lines changed

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

Lines changed: 37 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -259,68 +259,58 @@ describe("[Unit] ElementAssertion.test.ts", () => {
259259
expect(() => test.toHaveAllClasses("foo", "bar", "baz"))
260260
.toThrowError(AssertionError)
261261
.toHaveMessage('Expected the element to have all of these classes: "foo bar baz"');
262-
262+
263263
expect(test.not.toHaveAllClasses("foo", "bar", "baz")).toBeEqual(test);
264264
});
265265
});
266266
});
267-
267+
268268
describe(".toHaveStyle", () => {
269-
context("when the style is passed as a string", () => {
270-
context("and the element has the expected style", () => {
271-
it("returns the assertion instance", () => {
272-
const { getByTestId } = render(<div className="foo bar test" style={{ display: "flex", color: "red", border: "1px solid black" }} data-testid="test-div" />);
273-
const divTest = getByTestId("test-div");
274-
const test = new ElementAssertion(divTest);
275-
276-
expect(test.toHaveStyle("display: flex; color: red; border: 1px solid black")).toBeEqual(test);
277-
278-
expect(() => test.not.toHaveStyle("display: flex; color: red; border: 1px solid black"))
279-
.toThrowError(AssertionError)
280-
.toHaveMessage('Expected the element to NOT have {"display":"flex","color":"rgb(255, 0, 0)","border":"1px solid black"} style');
281-
});
282-
});
269+
context("when the element has the expected style", () => {
270+
it("returns the assertion instance", () => {
271+
const { getByTestId } = render(
272+
<div
273+
className="foo bar test"
274+
style={{ border: "1px solid black", color: "red", display: "flex" }}
275+
data-testid="test-div"
276+
/>);
277+
const divTest = getByTestId("test-div");
278+
const test = new ElementAssertion(divTest);
283279

284-
context("and the element does not have the expected style", () => {
285-
it("throws an assertion error", () => {
286-
const { getByTestId } = render(<div className="foo bar test" style={{ display: "flex", color: "red" }} data-testid="test-div" />);
287-
const divTest = getByTestId("test-div");
288-
const test = new ElementAssertion(divTest);
289-
290-
expect(test.not.toHaveStyle("color: red; display: flex; border: 1px solid black;")).toBeEqual(test);
280+
expect(test.toHaveStyle({ border: "1px solid black", color: "red", display: "flex" })).toBeEqual(test);
291281

292-
});
282+
expect(() => test.not.toHaveStyle({ border: "1px solid black", color: "red", display: "flex" }))
283+
.toThrowError(AssertionError)
284+
.toHaveMessage(
285+
// eslint-disable-next-line max-len
286+
'Expected the element to NOT match the following style:\n{\n "border": "1px solid black",\n "color": "rgb(255, 0, 0)",\n "display": "flex"\n}',
287+
);
293288
});
294289
});
295290

296-
context("when the style is passed as an object", () => {
297-
context("and the element has the expected style", () => {
298-
it("returns the assertion instance", () => {
299-
const { getByTestId } = render(<div className="foo bar test" style={{ display: "flex", color: "red", border: "1px solid black" }} data-testid="test-div" />);
291+
context("when the element does not have the expected style", () => {
292+
it("throws an assertion error", () => {
293+
const { getByTestId } = render(
294+
<div
295+
className="foo bar test"
296+
style={{ color: "blue", display: "block" }}
297+
data-testid="test-div"
298+
/>,
299+
);
300+
300301
const divTest = getByTestId("test-div");
301302
const test = new ElementAssertion(divTest);
302-
303-
expect(test.toHaveStyle({color: "red", display: "flex", border: "1px solid black"})).toBeEqual(test);
304303

305-
expect(() => test.not.toHaveStyle({color: "red", display: "flex", border: "1px solid black"}))
304+
expect(() => test.toHaveStyle(({ border: "1px solid black", color: "red", display: "flex" })))
306305
.toThrowError(AssertionError)
307-
.toHaveMessage('Expected the element to NOT have {"color":"rgb(255, 0, 0)","display":"flex","border":"1px solid black"} style');
308-
309-
});
310-
});
306+
.toHaveMessage(
307+
// eslint-disable-next-line max-len
308+
'Expected the element to match the following style:\n{\n "border": "1px solid black",\n "color": "rgb(255, 0, 0)",\n "display": "flex"\n}',
309+
);
310+
311+
expect(test.not.toHaveStyle({ border: "1px solid black", color: "red", display: "flex" })).toBeEqual(test);
311312

312-
context("and the element does not have the expected style", () => {
313-
it("throws an assertion error", () => {
314-
const { getByTestId } = render(<div className="foo bar test" style={{ display: "block", color: "blue" }} data-testid="test-div" />);
315-
const divTest = getByTestId("test-div");
316-
const test = new ElementAssertion(divTest);
317-
318-
expect(() => test.toHaveStyle(({ color: "red", display: "flex", border: "1px solid black" })))
319-
.toThrowError(AssertionError)
320-
.toHaveMessage("Expected the element to have {\"color\":\"rgb(255, 0, 0)\",\"display\":\"flex\",\"border\":\"1px solid black\"} style");
321-
322313
});
323314
});
324-
});
325315
});
326-
})
316+
});

0 commit comments

Comments
 (0)