Skip to content

Commit

Permalink
Add inverted errors and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsiher committed Oct 4, 2024
1 parent 03e9e4a commit 18f9d98
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/dom/test/unit/lib/ElementAssertion.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,12 @@ describe("[Unit] ElementAssertion.test.ts", () => {
const divTest = await findByTestId("classTest");
divTest.className = "foo bar";
const test = new ElementAssertion(divTest);

expect(test.toHaveClass("foo")).toBeEqual(test);

expect(() => test.not.toHaveClass("foo"))
.toThrowError(AssertionError)
.toHaveMessage("Expected the element to NOT have class(es): \"foo\"");
});
});

Expand All @@ -191,9 +196,12 @@ describe("[Unit] ElementAssertion.test.ts", () => {
const divTest = await findByTestId("classTest");
divTest.className = "foo";
const test = new ElementAssertion(divTest);

expect(() => test.toHaveClass("bar"))
.toThrowError(AssertionError)
.toHaveMessage("Expected the element to have class(es): \"bar\"");

expect(test.not.toHaveClass("bar")).toBeEqual(test);
});
});

Expand All @@ -203,7 +211,12 @@ describe("[Unit] ElementAssertion.test.ts", () => {
const divTest = await findByTestId("classTest");
divTest.className = "foo bar";
const test = new ElementAssertion(divTest);

expect(test.toHaveClass(["foo", "bar"], { exact: true })).toBeEqual(test);

expect(() => test.not.toHaveClass(["foo", "bar"], { exact: true }))
.toThrowError(AssertionError)
.toHaveMessage("Expected the element to NOT have exactly these classes: \"foo bar\"");
});
});

Expand All @@ -213,9 +226,12 @@ describe("[Unit] ElementAssertion.test.ts", () => {
const divTest = await findByTestId("classTest");
divTest.className = "foo bar extra";
const test = new ElementAssertion(divTest);

expect(() => test.toHaveClass(["foo", "bar"], { exact: true }))
.toThrowError(AssertionError)
.toHaveMessage("Expected the element to have exactly these classes: \"foo bar\"");

expect(test.not.toHaveClass(["foo", "bar"], { exact: true })).toBeEqual(test);
});
});
});
Expand Down

0 comments on commit 18f9d98

Please sign in to comment.