Skip to content

Commit b2804a1

Browse files
authored
fix(browser): update expect.element type to match the implementation (#8597)
1 parent 7a66112 commit b2804a1

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

packages/browser/matchers.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ declare module 'vitest' {
2222
* You can set default timeout via `expect.poll.timeout` option in the config.
2323
* @see {@link https://vitest.dev/api/expect#poll}
2424
*/
25-
element: <T extends Element | Locator | null>(element: T, options?: ExpectPollOptions) => PromisifyDomAssertion<Awaited<Element | null>>
25+
element: <T extends HTMLElement | SVGElement | null | Locator>(element: T, options?: ExpectPollOptions) => PromisifyDomAssertion<Awaited<HTMLElement | SVGElement | null>>
2626
}
2727
}
2828

packages/browser/src/client/tester/expect-element.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import type { Locator } from '@vitest/browser/context'
2-
import type { ExpectPollOptions } from 'vitest'
2+
import type { ExpectPollOptions, PromisifyDomAssertion } from 'vitest'
33
import { chai, expect } from 'vitest'
44
import { getType } from 'vitest/internal/browser'
55
import { matchers } from './expect'
66
import { processTimeoutOptions } from './utils'
77

88
const kLocator = Symbol.for('$$vitest:locator')
99

10-
function element<T extends HTMLElement | SVGElement | null | Locator>(elementOrLocator: T, options?: ExpectPollOptions): unknown {
10+
function element<T extends HTMLElement | SVGElement | null | Locator>(elementOrLocator: T, options?: ExpectPollOptions): PromisifyDomAssertion<HTMLElement | SVGElement | null> {
1111
if (elementOrLocator != null && !(elementOrLocator instanceof HTMLElement) && !(elementOrLocator instanceof SVGElement) && !(kLocator in elementOrLocator)) {
1212
throw new Error(`Invalid element or locator: ${elementOrLocator}. Expected an instance of HTMLElement, SVGElement or Locator, received ${getType(elementOrLocator)}`)
1313
}
@@ -50,5 +50,4 @@ function element<T extends HTMLElement | SVGElement | null | Locator>(elementOrL
5050
}
5151

5252
expect.extend(matchers)
53-
// Vitest typecheck doesn't pick up this assignment for some reason
54-
Object.assign(expect, { element })
53+
expect.element = element

0 commit comments

Comments
 (0)