mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-14 18:01:06 +00:00
test(button-set): add unit tests
This commit is contained in:
parent
5bff894ed7
commit
b9de4591be
3 changed files with 36 additions and 14 deletions
|
@ -1,14 +0,0 @@
|
||||||
<script lang="ts">
|
|
||||||
import { Button, ButtonSet } from "carbon-components-svelte";
|
|
||||||
import Login from "carbon-icons-svelte/lib/Login.svelte";
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<ButtonSet>
|
|
||||||
<Button kind="secondary">Cancel</Button>
|
|
||||||
<Button>Submit</Button>
|
|
||||||
</ButtonSet>
|
|
||||||
|
|
||||||
<ButtonSet stacked>
|
|
||||||
<Button icon={Login}>Log in</Button>
|
|
||||||
<Button kind="ghost">Sign up</Button>
|
|
||||||
</ButtonSet>
|
|
10
tests/ButtonSet/ButtonSet.test.svelte
Normal file
10
tests/ButtonSet/ButtonSet.test.svelte
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<script lang="ts">
|
||||||
|
import { ButtonSet, Button } from "carbon-components-svelte";
|
||||||
|
|
||||||
|
export let stacked = false;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<ButtonSet data-testid="button-set" {stacked}>
|
||||||
|
<Button kind="secondary">Cancel</Button>
|
||||||
|
<Button>Submit</Button>
|
||||||
|
</ButtonSet>
|
26
tests/ButtonSet/ButtonSet.test.ts
Normal file
26
tests/ButtonSet/ButtonSet.test.ts
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
import { render, screen } from "@testing-library/svelte";
|
||||||
|
import ButtonSet from "./ButtonSet.test.svelte";
|
||||||
|
|
||||||
|
describe("ButtonSet", () => {
|
||||||
|
it("renders buttons juxtaposed by default", () => {
|
||||||
|
render(ButtonSet);
|
||||||
|
|
||||||
|
const buttonSet = screen.getByTestId("button-set");
|
||||||
|
expect(buttonSet).toBeInTheDocument();
|
||||||
|
expect(buttonSet).toHaveClass("bx--btn-set");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("renders buttons vertically when stacked prop is true", () => {
|
||||||
|
render(ButtonSet, { stacked: true });
|
||||||
|
|
||||||
|
const buttonSet = screen.getByTestId("button-set");
|
||||||
|
expect(buttonSet).toBeInTheDocument();
|
||||||
|
expect(buttonSet).toHaveClass("bx--btn-set");
|
||||||
|
expect(buttonSet).toHaveClass("bx--btn-set--stacked");
|
||||||
|
|
||||||
|
const buttons = screen.getAllByRole("button");
|
||||||
|
expect(buttons).toHaveLength(2);
|
||||||
|
expect(buttons[0]).toHaveTextContent("Cancel");
|
||||||
|
expect(buttons[1]).toHaveTextContent("Submit");
|
||||||
|
});
|
||||||
|
});
|
Loading…
Add table
Add a link
Reference in a new issue