Skip to content

Commit 73155c8

Browse files
fix: implement tick in each method that acts on the tree to ensure observed mutations are handled first
1 parent 14bc767 commit 73155c8

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

src/Virtual.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ const observeDOM = (function () {
108108
};
109109
})();
110110

111+
async function tick() {
112+
return await new Promise<void>((resolve) => setTimeout(() => resolve()));
113+
}
114+
111115
export class Virtual implements ScreenReader {
112116
#activeNode: AccessibilityNode | null = null;
113117
#container: Node | null = null;
@@ -256,6 +260,7 @@ export class Virtual implements ScreenReader {
256260
*/
257261
async previous() {
258262
this.#checkContainer();
263+
await tick();
259264

260265
const tree = this.#getAccessibilityTree();
261266

@@ -277,6 +282,7 @@ export class Virtual implements ScreenReader {
277282
*/
278283
async next() {
279284
this.#checkContainer();
285+
await tick();
280286

281287
const tree = this.#getAccessibilityTree();
282288

@@ -301,6 +307,7 @@ export class Virtual implements ScreenReader {
301307
*/
302308
async act() {
303309
this.#checkContainer();
310+
await tick();
304311

305312
if (!this.#activeNode) {
306313
return;
@@ -360,6 +367,7 @@ export class Virtual implements ScreenReader {
360367
*/
361368
async press(key: string) {
362369
this.#checkContainer();
370+
await tick();
363371

364372
if (!this.#activeNode) {
365373
return;
@@ -406,6 +414,7 @@ export class Virtual implements ScreenReader {
406414
*/
407415
async type(text: string) {
408416
this.#checkContainer();
417+
await tick();
409418

410419
if (!this.#activeNode) {
411420
return;
@@ -424,6 +433,7 @@ export class Virtual implements ScreenReader {
424433
*/
425434
async perform() {
426435
this.#checkContainer();
436+
await tick();
427437

428438
// TODO: decide what this means as there is no established "common" command
429439
// set for different screen readers.
@@ -438,6 +448,7 @@ export class Virtual implements ScreenReader {
438448
*/
439449
async click({ button = "left", clickCount = 1 } = {}) {
440450
this.#checkContainer();
451+
await tick();
441452

442453
if (!this.#activeNode) {
443454
return;

test/int/next.int.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ describe("next", () => {
7474
const currentElement = getByRole(document.body, "navigation");
7575
document.body.removeChild(currentElement);
7676

77-
await new Promise<void>((resolve) => setTimeout(() => resolve()));
7877
await virtual.next();
7978

8079
expect(await virtual.spokenPhraseLog()).toEqual([

test/int/previous.int.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ describe("previous", () => {
7878
const currentElement = getByRole(document.body, "navigation");
7979
document.body.removeChild(currentElement);
8080

81-
await new Promise<void>((resolve) => setTimeout(() => resolve()));
8281
await virtual.previous();
8382

8483
expect(await virtual.spokenPhraseLog()).toEqual([

0 commit comments

Comments
 (0)