-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(browser): only use locator.element on last expect.element attempt (…
- Loading branch information
Showing
5 changed files
with
108 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { page } from '@vitest/browser/context' | ||
import { expect, test, vi } from 'vitest' | ||
|
||
// element selector uses prettyDOM under the hood, which is an expensive call | ||
// that should not be called on each failed locator attempt to avoid memory leak: | ||
// https://github.com/vitest-dev/vitest/issues/7139 | ||
test('should only use element selector on last expect.element attempt', async () => { | ||
const div = document.createElement('div') | ||
const spanString = '<span>test</span>' | ||
div.innerHTML = spanString | ||
document.body.append(div) | ||
|
||
const locator = page.getByText('non-existent') | ||
const locatorElementMock = vi.spyOn(locator, 'element') | ||
const locatorQueryMock = vi.spyOn(locator, 'query') | ||
|
||
try { | ||
await expect.element(locator, { timeout: 500, interval: 100 }).toBeInTheDocument() | ||
} | ||
catch {} | ||
|
||
expect(locatorElementMock).toBeCalledTimes(1) | ||
expect(locatorElementMock).toHaveBeenCalledAfter(locatorQueryMock) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters