Skip to content

Commit

Permalink
fix(browser): fix toHaveClass typing (#7383)
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa authored Feb 4, 2025
1 parent dc3fd3e commit 7ef238c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
3 changes: 1 addition & 2 deletions packages/browser/jest-dom.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,7 @@ declare namespace matchers {
* @see
* [testing-library/jest-dom#tohaveclass](https://github.com/testing-library/jest-dom#tohaveclass)
*/
toHaveClass(classNames: string, options?: {exact: boolean}): R
toHaveClass(...classNames: Array<string | RegExp>): R
toHaveClass(...classNames: (string | RegExp)[] | [string, options?: {exact: boolean}]): R
/**
* @description
* This allows you to check whether the given form element has the specified displayed value (the one the
Expand Down
14 changes: 14 additions & 0 deletions test/browser/test/dom.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ describe('dom related activity', () => {
expect(screenshotPath).toMatch(
/__screenshots__\/dom.test.ts\/dom-related-activity-renders-div-1.png/,
)

// test typing
if (0) {
await expect.element(div).toHaveClass('x', { exact: true })
await expect.element(div).toHaveClass('x', 'y')
await expect.element(div).toHaveClass('x', /y/)
await expect.element(div).toHaveClass(/x/, 'y')
await expect.element(div).toHaveClass('x', /y/, 'z')
await expect.element(div).toHaveClass(/x/, 'y', /z/)
// @ts-expect-error error
await expect.element(div).toHaveClass('x', { exact: 1234 })
// @ts-expect-error error
await expect.element(div).toHaveClass('x', 1234)
}
})

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

0 comments on commit 7ef238c

Please sign in to comment.