Skip to content

Commit 2017ea3

Browse files
nickrolfeCopilot
andcommitted
Assert checkbox state inside waitFor in RepoRow tests
The findCheckbox helper only waited for the vscode-checkbox element to exist, not for Lit to reflect the disabled property to an attribute, so the enabled/disabled assertions at each call site raced the async update. Move the assertion into the waitFor callback via an expected state argument so the retry loop waits for reflection. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 0f8ebf0f-6429-4147-b7eb-ffacf1a942da
1 parent 03d6d15 commit 2017ea3

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

extensions/ql-vscode/src/view/variant-analysis/__tests__/RepoRow.spec.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,20 @@ describe(RepoRow.name, () => {
3434
// which testing-library cannot reach), so find it by tag name instead. The
3535
// `disabled` property is reflected to a `disabled` attribute asynchronously by
3636
// Lit, so wait for the expected state.
37-
const findCheckbox = async (container: HTMLElement): Promise<HTMLElement> => {
37+
const findCheckbox = async (
38+
container: HTMLElement,
39+
expected: "enabled" | "disabled",
40+
): Promise<HTMLElement> => {
3841
return waitFor(() => {
3942
const checkbox = container.querySelector("vscode-checkbox");
4043
if (!checkbox) {
4144
throw new Error("Unable to find a vscode-checkbox element");
4245
}
46+
if (expected === "disabled") {
47+
expect(checkbox).toBeDisabled();
48+
} else {
49+
expect(checkbox).toBeEnabled();
50+
}
4351
return checkbox as HTMLElement;
4452
});
4553
};
@@ -418,17 +426,15 @@ describe(RepoRow.name, () => {
418426
status: VariantAnalysisRepoStatus.InProgress,
419427
});
420428

421-
const checkbox = await findCheckbox(container);
422-
expect(checkbox).toBeDisabled();
429+
await findCheckbox(container, "disabled");
423430
});
424431

425432
it("does not allow selecting the item if the item has not been downloaded", async () => {
426433
const { container } = render({
427434
status: VariantAnalysisRepoStatus.Succeeded,
428435
});
429436

430-
const checkbox = await findCheckbox(container);
431-
expect(checkbox).toBeDisabled();
437+
await findCheckbox(container, "disabled");
432438
});
433439

434440
it("does not allow selecting the item if the item has not been downloaded successfully", async () => {
@@ -440,8 +446,7 @@ describe(RepoRow.name, () => {
440446
},
441447
});
442448

443-
const checkbox = await findCheckbox(container);
444-
expect(checkbox).toBeDisabled();
449+
await findCheckbox(container, "disabled");
445450
});
446451

447452
it("allows selecting the item if the item has been downloaded", async () => {
@@ -454,7 +459,6 @@ describe(RepoRow.name, () => {
454459
},
455460
});
456461

457-
const checkbox = await findCheckbox(container);
458-
expect(checkbox).toBeEnabled();
462+
await findCheckbox(container, "enabled");
459463
});
460464
});

0 commit comments

Comments
 (0)