Skip to content

Commit 18f9d98

Browse files
committed
Add inverted errors and tests
1 parent 03e9e4a commit 18f9d98

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

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

+16
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,12 @@ describe("[Unit] ElementAssertion.test.ts", () => {
181181
const divTest = await findByTestId("classTest");
182182
divTest.className = "foo bar";
183183
const test = new ElementAssertion(divTest);
184+
184185
expect(test.toHaveClass("foo")).toBeEqual(test);
186+
187+
expect(() => test.not.toHaveClass("foo"))
188+
.toThrowError(AssertionError)
189+
.toHaveMessage("Expected the element to NOT have class(es): \"foo\"");
185190
});
186191
});
187192

@@ -191,9 +196,12 @@ describe("[Unit] ElementAssertion.test.ts", () => {
191196
const divTest = await findByTestId("classTest");
192197
divTest.className = "foo";
193198
const test = new ElementAssertion(divTest);
199+
194200
expect(() => test.toHaveClass("bar"))
195201
.toThrowError(AssertionError)
196202
.toHaveMessage("Expected the element to have class(es): \"bar\"");
203+
204+
expect(test.not.toHaveClass("bar")).toBeEqual(test);
197205
});
198206
});
199207

@@ -203,7 +211,12 @@ describe("[Unit] ElementAssertion.test.ts", () => {
203211
const divTest = await findByTestId("classTest");
204212
divTest.className = "foo bar";
205213
const test = new ElementAssertion(divTest);
214+
206215
expect(test.toHaveClass(["foo", "bar"], { exact: true })).toBeEqual(test);
216+
217+
expect(() => test.not.toHaveClass(["foo", "bar"], { exact: true }))
218+
.toThrowError(AssertionError)
219+
.toHaveMessage("Expected the element to NOT have exactly these classes: \"foo bar\"");
207220
});
208221
});
209222

@@ -213,9 +226,12 @@ describe("[Unit] ElementAssertion.test.ts", () => {
213226
const divTest = await findByTestId("classTest");
214227
divTest.className = "foo bar extra";
215228
const test = new ElementAssertion(divTest);
229+
216230
expect(() => test.toHaveClass(["foo", "bar"], { exact: true }))
217231
.toThrowError(AssertionError)
218232
.toHaveMessage("Expected the element to have exactly these classes: \"foo bar\"");
233+
234+
expect(test.not.toHaveClass(["foo", "bar"], { exact: true })).toBeEqual(test);
219235
});
220236
});
221237
});

0 commit comments

Comments
 (0)