Skip to content

Commit 2311067

Browse files
committed
Add tests for container pop
1 parent 65760bd commit 2311067

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/routes/+page.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,11 @@ toast.set(id, { next: 1 })`,
237237
{
238238
name: 'REMOVE ALL TOASTS FROM CONTAINER',
239239
code: `// Remove all toasts from "new" container
240-
toast.pop(i => i.target !== 'new')
240+
toast.pop({ target: 'new' })
241241
242242
// Or remove ALL active toasts from ALL containers
243243
toast.pop(0)`,
244-
run: () => toast.pop((i) => i.target !== 'new')
244+
run: () => toast.pop({ target: 'new' })
245245
},
246246
{
247247
name: 'SEND COMPONENT AS A MESSAGE',

tests/test.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,18 @@ test('can change dismiss btn char', async ({ page }) => {
193193
expect(btn).toBe('"x"')
194194
})
195195

196-
// Playwright currently does not provide a way to test this
196+
test('removes all toasts from a container target', async ({ page }) => {
197+
await page.goto('/')
198+
for (let a = 0; a < 3; a++) {
199+
await page.getByTestId('createNewToastContainer').click()
200+
}
201+
await page.getByTestId('removeAllToastsFromContainer').click()
202+
await expect(page.locator('._toastItem')).toHaveCount(0)
203+
})
204+
205+
// Playwright currently doesn't provide a way to test this
197206
// https://github.com/microsoft/playwright/issues/2286
207+
// TODO: migrate this Cypress test
198208
/*
199209
it('Toggles pause and resume on visibilitychange', () => {
200210
cy.get('[data-btn=default]')
@@ -249,3 +259,12 @@ test('`push()` accepts both string and obj', async ({ page }) => {
249259
await page.evaluate(`window.toast.push({msg:'push with obj'})`)
250260
await expect(page.getByText('push with obj')).toBeVisible()
251261
})
262+
263+
test('removes toasts from container via filter fn', async ({ page }) => {
264+
await page.goto('/', { waitUntil: 'networkidle' })
265+
for (let a = 0; a < 3; a++) {
266+
await page.getByTestId('createNewToastContainer').click()
267+
}
268+
await page.evaluate(`window.toast.pop(i=>i.target!=='new')`)
269+
await expect(page.locator('._toastItem')).toHaveCount(0)
270+
})

0 commit comments

Comments
 (0)