-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(dom): DOM - toHaveClass #134
base: main
Are you sure you want to change the base?
Conversation
6827334
to
18f9d98
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great @fonsiher. Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good so far, but I think we can improve things if we create 3 assertions instead of one 🙂
* - `exact` (boolean): When true, checks for an exact match of all classes. | ||
* @returns the assertion instance. | ||
*/ | ||
public toHaveClass(classNames: string | string[], options: { exact?: boolean; } = {}): this { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about making more than one assertion instead of adding the options param? To me, it'll provide more readability if we have the following:
expect(elem).toHaveClass("w-full"); // single arg
expect(elem).toHaveAnyClass("w-full", "flex"); // variadic args
expect(elem).toHaveAllClasses("w-full", "flex", "gap-8"); // variadic args
it("returns the assertion instance", async () => { | ||
const { findByTestId } = render(<HaveClassTestComponent />); | ||
const divTest = await findByTestId("classTest"); | ||
divTest.className = "foo bar"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to use divTest.classList.add("foo", "bar")
instead? 🤔
Added the toHaveClass matcher.