Skip to content

Commit

Permalink
Test Description (#369)
Browse files Browse the repository at this point in the history
The `expect(link.href).toContain(...)` wasn't actually testing anything. With `link="https://servicenow.github.io/azimuth/"`, the resulting `href` ended up being `https://servicenow.github.io/azimuth/main/https://servicenow.github.io/azimuth/`, so of course it contained `https://servicenow.github.io/azimuth/`. This test would pass even if we changed the base documentation URL.

Solution: Let's assert equality instead of `toContain`.
  • Loading branch information
JosephMarinier committed Jan 10, 2023
1 parent fe49454 commit d0e7d6b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
3 changes: 2 additions & 1 deletion webapp/src/components/AccordionLayout.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ describe("AccordionLayout", () => {
)
).toBeVisible();
const link: HTMLAnchorElement = screen.getByRole("link");
expect(link.href).toContain(
expect(link).toHaveAttribute(
"href",
"https://servicenow.github.io/azimuth/main/reference/configuration/project/"
);
screen.getByText("Learn more");
Expand Down
12 changes: 5 additions & 7 deletions webapp/src/components/Description.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,15 @@ describe("Description", () => {
});

it("should display description with both link and text", async () => {
renderWithTheme(
<Description
text="test description"
link="https://servicenow.github.io/azimuth/"
/>
);
renderWithTheme(<Description text="test description" link="potato" />);

screen.getByText("test description");

const link: HTMLAnchorElement = screen.getByRole("link");
expect(link.href).toContain("https://servicenow.github.io/azimuth/");
expect(link).toHaveAttribute(
"href",
"https://servicenow.github.io/azimuth/main/potato"
);
screen.getByText("Learn more");
screen.getByTestId("OpenInNewIcon");
});
Expand Down

0 comments on commit d0e7d6b

Please sign in to comment.