chore: use clock.restore for locator test (#10597)

This commit is contained in:
jrandolf 2023-07-20 10:23:37 +02:00 committed by GitHub
parent 03adf4189e
commit 5a411ca629
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 33 deletions

View File

@ -2423,12 +2423,6 @@
"parameters": ["firefox", "webDriverBiDi"], "parameters": ["firefox", "webDriverBiDi"],
"expectations": ["SKIP"] "expectations": ["SKIP"]
}, },
{
"testIdPattern": "[locator.spec] Locator Locator.prototype.expect should resolve as soon as the predicate matches",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["chrome", "webDriverBiDi"],
"expectations": ["TIMEOUT"]
},
{ {
"testIdPattern": "[mouse.spec] Mouse should reset properly", "testIdPattern": "[mouse.spec] Mouse should reset properly",
"platforms": ["darwin", "linux", "win32"], "platforms": ["darwin", "linux", "win32"],

View File

@ -540,41 +540,16 @@ describe('Locator', function () {
}); });
describe('Locator.prototype.expect', () => { describe('Locator.prototype.expect', () => {
it('should not resolve if the predicate does not match', async () => {
const clock = sinon.useFakeTimers({
shouldClearNativeTimers: true,
});
try {
const {page} = await getTestState();
page.setDefaultTimeout(5000);
await page.setContent(`<div>test</div>`);
const result = page
.locator('::-p-text(test)')
.expect((element): Promise<boolean> => {
return Promise.resolve(
element.getAttribute('clickable') === 'true'
);
})
.hover();
clock.tick(5100);
await expect(result).rejects.toEqual(
new TimeoutError('waitForFunction timed out. The timeout is 5000ms.')
);
} finally {
clock.restore();
}
});
it('should resolve as soon as the predicate matches', async () => { it('should resolve as soon as the predicate matches', async () => {
const clock = sinon.useFakeTimers({ const clock = sinon.useFakeTimers({
shouldClearNativeTimers: true, shouldClearNativeTimers: true,
}); });
try { try {
const {page} = await getTestState(); const {page} = await getTestState();
page.setDefaultTimeout(5000);
await page.setContent(`<div>test</div>`); await page.setContent(`<div>test</div>`);
const result = page const result = page
.locator('::-p-text(test)') .locator('::-p-text(test)')
.setTimeout(5000)
.expect(async element => { .expect(async element => {
return element.getAttribute('clickable') === 'true'; return element.getAttribute('clickable') === 'true';
}) })
@ -586,7 +561,7 @@ describe('Locator', function () {
await page.evaluate(() => { await page.evaluate(() => {
document.querySelector('div')?.setAttribute('clickable', 'true'); document.querySelector('div')?.setAttribute('clickable', 'true');
}); });
clock.tick(2000); clock.restore();
await expect(result).resolves.toEqual(undefined); await expect(result).resolves.toEqual(undefined);
} finally { } finally {
clock.restore(); clock.restore();