Skip to content

Commit 77bf054

Browse files
Rounding out icon tests.
1 parent a5f4ade commit 77bf054

File tree

4 files changed

+74
-232
lines changed

4 files changed

+74
-232
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
"test": "run-s clean analyze build test:unit",
3939
"test:ci": "run-s build:tools build:extract-css build:styles build:unit build:types build:copy-assets test:unit",
4040
"test:unit": "CI=TRUE vitest -c ./vitest.config.js --test-timeout=1000",
41-
"test:watch": "vitest -c ./vitest.config.js --test-timeout=1000"
41+
"test:unit-watch": "vitest -c ./vitest.config.js --test-timeout=1000",
42+
"test:watch": "run-s clean analyze build test:unit-watch"
4243
},
4344
"type": "module",
4445
"exports": {

src/ak-brand/ak-brand.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ describe("ak-brand component", () => {
3434
alt: "Test Logo",
3535
});
3636

37-
const brand = await page.getBrand();
38-
const img = await page.getBrandImage();
37+
const brand = page.getBrand();
38+
const img = page.getBrandImage();
3939

4040
await expect.element(brand).toBeVisible();
4141
await expect.element(img).toBeVisible();
@@ -49,8 +49,8 @@ describe("ak-brand component", () => {
4949
alt: "Test Logo",
5050
});
5151

52-
const brand = await page.getBrand();
53-
const img = await page.getBrandImage();
52+
const brand = page.getBrand();
53+
const img = page.getBrandImage();
5454
await expect.element(brand).toBeVisible();
5555
await expect.element(img).toBeVisible();
5656
await expect.element(img).not.toHaveAttribute("src");

src/ak-button/ak-button.test.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ describe("ak-button component", () => {
2020
};
2121

2222
it("renders as a button by default", async () => {
23-
const { getByRole, getByText } = renderComponent("Click here");
23+
const { getByRole } = renderComponent("Click here");
2424
const button = await getByRole("button");
25-
expect(await button.getByText("Click here")).toBeTruthy();
26-
const element = await button.element();
25+
expect(button.getByText("Click here")).toBeTruthy();
26+
const element = button.element();
2727
expect(element.tagName).toBe("BUTTON");
2828
});
2929

@@ -34,62 +34,62 @@ describe("ak-button component", () => {
3434
});
3535

3636
// When variant="link", renders <a> tag instead of <button>
37-
const link = await getByText("Click to leave");
37+
const link = getByText("Click to leave");
3838
await expect.element(link).toBeTruthy();
3939
await expect.element(link).toHaveAttribute("href", "https://example.com");
40-
const element = await getByRole("link").element();
40+
const element = getByRole("link").element();
4141
expect(element.tagName).toBe("A");
4242

4343
// Verify slotted text content
4444
const component = document.querySelector("ak-button");
45-
await expect(component?.textContent?.trim()).toBe("Click to leave");
45+
expect(component?.textContent?.trim()).toBe("Click to leave");
4646
});
4747

4848
it("applies disabled state when specified", async () => {
49-
const { getByRole, getByText } = renderComponent("Click here", { "?disabled": true });
49+
const { getByRole } = renderComponent("Click here", { "?disabled": true });
5050
const button = await getByRole("button");
51-
expect(await button.getByText("Click here")).toBeTruthy();
52-
const element = await button.element();
51+
expect(button.getByText("Click here")).toBeTruthy();
52+
const element = button.element();
5353
expect(element.tagName).toBe("BUTTON");
5454
await expect.element(button).toHaveAttribute("disabled");
5555
});
5656

5757
it("triggers click events", async () => {
5858
const { getByRole } = renderComponent("Click here");
5959
const component = document.querySelector("ak-button");
60-
await expect(component).toBeTruthy();
60+
await expect.element(component).toBeTruthy();
6161

6262
let buttonClicked = false;
6363
component!.addEventListener("click", () => {
6464
buttonClicked = true;
6565
});
6666

6767
const button = await getByRole("button");
68-
await expect((await button.element()).tagName).toBe("BUTTON");
68+
expect(button.element().tagName).toBe("BUTTON");
6969
await button.click();
7070
expect(buttonClicked).toBe(true);
7171
});
7272

7373
it("does not trigger click events when disabled", async () => {
7474
const { getByRole } = renderComponent("Click here", { "?disabled": true });
7575
const component = document.querySelector("ak-button");
76-
await expect(component).toBeTruthy();
76+
expect(component).toBeTruthy();
7777

7878
let buttonClicked = false;
7979
component!.addEventListener("click", () => {
8080
buttonClicked = true;
8181
});
8282

8383
const button = await getByRole("button");
84-
await expect((await button.element()).tagName).toBe("BUTTON");
84+
expect(button.element().tagName).toBe("BUTTON");
8585
// Playwright will normally avoid clicking a button that is marked "disabled." We want it to
8686
// try anyway.
8787
await button.click({ force: true });
8888
expect(buttonClicked).toBe(false);
8989
});
9090

9191
it("when a link, it does not have an href when disabled", async () => {
92-
const { getByRole, getByText } = renderComponent("Click to leave", {
92+
renderComponent("Click to leave", {
9393
"variant": "link",
9494
"href": "https://example.com",
9595
"?disabled": true,
@@ -98,9 +98,9 @@ describe("ak-button component", () => {
9898
const component = document.querySelector("ak-button");
9999
const anchor = await vi.waitUntil(() => component?.shadowRoot?.querySelector("a"));
100100
expect(anchor).not.toBeNull();
101-
const element = await page.elementLocator(anchor!);
102-
await expect(element).toBeVisible();
103-
await expect(element).toHaveAttribute("id", "main");
104-
await expect(element).not.toHaveAttribute("href");
101+
const element = page.elementLocator(anchor!);
102+
await expect.element(element).toBeVisible();
103+
await expect.element(element).toHaveAttribute("id", "main");
104+
await expect.element(element).not.toHaveAttribute("href");
105105
});
106106
});

0 commit comments

Comments
 (0)