Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/stacks-svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"@stackoverflow/stacks-icons-legacy": "npm:@stackoverflow/stacks-icons@^6.9.0",
"@stackoverflow/stacks-utils": "^1.0.0",
"svelte-floating-ui": "^1.6.2",
"svelte-sonner": "^1.1.1"
"svelte-sonner": "^1.2.1"
},
"files": [
"lib",
Expand Down
23 changes: 19 additions & 4 deletions packages/stacks-svelte/src/components/Toast/Toast.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,29 @@ import { expect } from "@open-wc/testing";
import { render, screen, waitFor } from "@testing-library/svelte";
import userEvent from "@testing-library/user-event";
import sinon from "sinon";
import { toast } from "svelte-sonner";
import { createRawSnippet, mount, unmount } from "svelte";
import NoticeAction from "../Notice/NoticeAction.svelte";

import Toaster, { showToast, hideToast } from "./Toast.svelte";

async function dismissToasts() {
try {
// Dismiss while the Toaster is mounted, before automatic DOM cleanup.
toast.dismiss();
await waitFor(
() =>
expect(document.querySelector("[data-sonner-toast]")).to.not
.exist
);
} finally {
sinon.restore();
}
}

describe("showToast", () => {
afterEach(dismissToasts);

it("should render a default toast component", async () => {
render(Toaster);
showToast("Test Toast");
Expand Down Expand Up @@ -65,7 +82,6 @@ describe("showToast", () => {
await waitFor(
() => expect(screen.queryByText("Test Toast")).to.not.exist
);
clock.restore();
});

it("should never close automatically when transient is false", async () => {
Expand All @@ -78,7 +94,6 @@ describe("showToast", () => {
await waitFor(() => expect(screen.getByText("Test Toast")).to.exist);
await clock.tickAsync(15000);
expect(screen.getByText("Test Toast")).to.exist;
clock.restore();
});

it("should close the toast based on the duration option when provided", async () => {
Expand All @@ -93,7 +108,6 @@ describe("showToast", () => {
await waitFor(
() => expect(screen.queryByText("Test Toast")).to.not.exist
);
clock.restore();
});

it("should render other actions in the toast when provided", async () => {
Expand Down Expand Up @@ -148,7 +162,6 @@ describe("showToast", () => {
expect(onCloseSpy).to.have.been.called;
expect(onAutoCloseSpy).to.have.been.called;
expect(onUserCloseSpy).to.not.have.been.called;
clock.restore();
});

it("should call onClose and onUserClose callbacks when the toast is closed by the user", async () => {
Expand Down Expand Up @@ -192,6 +205,8 @@ describe("showToast", () => {
});

describe("hideToast", () => {
afterEach(dismissToasts);

it("should close a toast programmatically", async () => {
render(Toaster);
const toastId = showToast("Test Toast", { transient: false });
Expand Down
Loading