Skip to content

Commit ba4f278

Browse files
committed
Simplify a html step
This is now possible when eg. "50% (1 / 2) passed" is displayed.
1 parent 1f99b67 commit ba4f278

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

features/step_definitions/html_steps.ts

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import fs from "node:fs/promises";
33
import path from "node:path";
44

55
import { Then } from "@cucumber/cucumber";
6-
import { findAllByText, findByText } from "@testing-library/dom";
6+
import { findByText } from "@testing-library/dom";
77
import { JSDOM } from "jsdom";
88

9+
import { ensure } from "../../lib/helpers/assertions";
910
import { findAllByAccordionComponent } from "../support/accordion";
1011
import ICustomWorld from "../support/ICustomWorld";
1112

@@ -36,34 +37,26 @@ Then(
3637

3738
Then(
3839
"the HTML should display {int} executed scenario(s)",
39-
async function (this: ICustomWorld, n: number) {
40+
async function (this: ICustomWorld, expected: number) {
4041
const dom = await JSDOM.fromFile(
4142
path.join(this.tmpDir, "cucumber-report.html"),
4243
{ runScripts: "dangerously" },
4344
);
4445

4546
// configure({ defaultIgnore: "comments, script, style, link, g, path" });
4647

47-
const AccordionItemButtons = await findAllByAccordionComponent(
48+
const dd = await findByText(
4849
dom.window.document.documentElement,
49-
"AccordionItemButton",
50+
/\d+% \(\d+ \/ \d+\) passed/,
51+
{ selector: "span" },
5052
);
5153

52-
for (const AccordionItemButton of AccordionItemButtons) {
53-
if (
54-
AccordionItemButton.attributes.getNamedItem("aria-expanded")?.value ===
55-
"false"
56-
) {
57-
AccordionItemButton.click();
58-
}
59-
}
60-
61-
const spans = await findAllByText(
62-
dom.window.document.documentElement,
63-
/Scenario/,
54+
const [, actual] = ensure(
55+
dd.textContent!.match(/\d+% \(\d+ \/ (\d+)\) passed/),
56+
"Expected a match",
6457
);
6558

66-
assert.equal(spans.length, n);
59+
assert.equal(actual, expected);
6760
},
6861
);
6962

0 commit comments

Comments
 (0)