Skip to content

Commit 7ef238c

Browse files
authoredFeb 4, 2025··
fix(browser): fix toHaveClass typing (#7383)
1 parent dc3fd3e commit 7ef238c

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed
 

‎packages/browser/jest-dom.d.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,7 @@ declare namespace matchers {
260260
* @see
261261
* [testing-library/jest-dom#tohaveclass](https://github.com/testing-library/jest-dom#tohaveclass)
262262
*/
263-
toHaveClass(classNames: string, options?: {exact: boolean}): R
264-
toHaveClass(...classNames: Array<string | RegExp>): R
263+
toHaveClass(...classNames: (string | RegExp)[] | [string, options?: {exact: boolean}]): R
265264
/**
266265
* @description
267266
* This allows you to check whether the given form element has the specified displayed value (the one the

‎test/browser/test/dom.test.ts

+14
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,20 @@ describe('dom related activity', () => {
3131
expect(screenshotPath).toMatch(
3232
/__screenshots__\/dom.test.ts\/dom-related-activity-renders-div-1.png/,
3333
)
34+
35+
// test typing
36+
if (0) {
37+
await expect.element(div).toHaveClass('x', { exact: true })
38+
await expect.element(div).toHaveClass('x', 'y')
39+
await expect.element(div).toHaveClass('x', /y/)
40+
await expect.element(div).toHaveClass(/x/, 'y')
41+
await expect.element(div).toHaveClass('x', /y/, 'z')
42+
await expect.element(div).toHaveClass(/x/, 'y', /z/)
43+
// @ts-expect-error error
44+
await expect.element(div).toHaveClass('x', { exact: 1234 })
45+
// @ts-expect-error error
46+
await expect.element(div).toHaveClass('x', 1234)
47+
}
3448
})
3549

3650
test('resolves base64 screenshot', async () => {

0 commit comments

Comments
 (0)
Please sign in to comment.