mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
chore: use clock.restore for locator test (#10597)
This commit is contained in:
parent
03adf4189e
commit
5a411ca629
@ -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"],
|
||||
|
@ -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(`<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 () => {
|
||||
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)')
|
||||
.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();
|
||||
|
Loading…
Reference in New Issue
Block a user