From 5a411ca629263bbea07544120391a4c4e4fb6915 Mon Sep 17 00:00:00 2001 From: jrandolf <101637635+jrandolf@users.noreply.github.com> Date: Thu, 20 Jul 2023 10:23:37 +0200 Subject: [PATCH] chore: use clock.restore for locator test (#10597) --- test/TestExpectations.json | 6 ------ test/src/locator.spec.ts | 29 ++--------------------------- 2 files changed, 2 insertions(+), 33 deletions(-) diff --git a/test/TestExpectations.json b/test/TestExpectations.json index 055622bbda3..03aff4b26c9 100644 --- a/test/TestExpectations.json +++ b/test/TestExpectations.json @@ -2423,12 +2423,6 @@ "parameters": ["firefox", "webDriverBiDi"], "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", "platforms": ["darwin", "linux", "win32"], diff --git a/test/src/locator.spec.ts b/test/src/locator.spec.ts index 3a34ef3e47a..a938128d130 100644 --- a/test/src/locator.spec.ts +++ b/test/src/locator.spec.ts @@ -540,41 +540,16 @@ describe('Locator', function () { }); 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(`
test
`); - const result = page - .locator('::-p-text(test)') - .expect((element): Promise => { - 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 () => { const clock = sinon.useFakeTimers({ shouldClearNativeTimers: true, }); try { const {page} = await getTestState(); - page.setDefaultTimeout(5000); await page.setContent(`
test
`); const result = page .locator('::-p-text(test)') + .setTimeout(5000) .expect(async element => { return element.getAttribute('clickable') === 'true'; }) @@ -586,7 +561,7 @@ describe('Locator', function () { await page.evaluate(() => { document.querySelector('div')?.setAttribute('clickable', 'true'); }); - clock.tick(2000); + clock.restore(); await expect(result).resolves.toEqual(undefined); } finally { clock.restore();