-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathWaitForHelper.test.ts
More file actions
67 lines (55 loc) · 1.99 KB
/
WaitForHelper.test.ts
File metadata and controls
67 lines (55 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import assert from 'node:assert';
import {describe, it} from 'node:test';
import sinon from 'sinon';
import {WaitForHelper} from '../src/WaitForHelper.js';
import {type Page, type CdpPage} from '../src/third_party/index.js';
class MockPage {
#client = {
on() {},
off() {},
};
evaluateHandle() {}
waitForNavigation() {}
_client() {
return this.#client;
}
}
describe('WaitForHelper', () => {
it('should wait for stable DOM', async () => {
const page = new MockPage();
const helper = new WaitForHelper(page as unknown as Page, 1, 1);
const evaluateHandle = sinon.stub(page, 'evaluateHandle').resolves({
evaluate: () => Promise.resolve(),
dispose: () => Promise.resolve(),
} as any);
await helper.waitForStableDom();
assert.ok(evaluateHandle.calledOnce);
});
it('should wait for navigation started', async () => {
const page = new MockPage() as unknown as CdpPage;
const client = page._client();
const on = sinon.spy(client, 'on');
const off = sinon.spy(client, 'off');
const helper = new WaitForHelper(page as unknown as Page, 1, 1);
await helper.waitForNavigationStarted();
assert.ok(on.calledOnceWith('Page.frameStartedNavigating', sinon.match.func));
});
it('should wait for events after action', async () => {
const page = new MockPage();
const helper = new WaitForHelper(page as unknown as Page, 1, 1);
const waitForNavigationStarted = sinon.stub(helper, 'waitForNavigationStarted').resolves(true);
const waitForNavigation = sinon.stub(page, 'waitForNavigation').resolves();
const waitForStableDom = sinon.stub(helper, 'waitForStableDom').resolves();
const action = sinon.spy();
await helper.waitForEventsAfterAction(action);
assert.ok(waitForNavigationStarted.calledOnce);
assert.ok(waitForNavigation.calledOnce);
assert.ok(waitForStableDom.calledOnce);
assert.ok(action.calledOnce);
});
});