Skip to content

Commit 7223b76

Browse files
committed
Add visibilitychange test
1 parent 2769c38 commit 7223b76

File tree

1 file changed

+19
-37
lines changed

1 file changed

+19
-37
lines changed

tests/test.js

Lines changed: 19 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ test('removes all toast from particular container', async ({ page }) => {
115115
})
116116

117117
test('renders custom component and is reactive', async ({ page }) => {
118-
await page.goto('/', { waitUntil: 'networkidle' })
118+
await page.goto('/')
119119
await page.getByTestId('sendComponentAsAMessage').click()
120120
await expect(page.locator('._toastItem h1')).toHaveText('A Dummy Cookie Component')
121121
await page.getByTestId('removeLastToast').click()
@@ -210,43 +210,25 @@ test('removes all toasts from a container target', async ({ page }) => {
210210
await expect(page.locator('._toastItem')).toHaveCount(0)
211211
})
212212

213-
// Playwright currently doesn't provide a way to test this
214-
// https://github.com/microsoft/playwright/issues/2286
215-
// TODO: migrate this Cypress test
216-
/*
217-
it('Toggles pause and resume on visibilitychange', () => {
218-
cy.get('[data-btn=default]')
219-
.click()
220-
.document()
221-
.then((doc) => {
222-
cy.stub(doc, 'hidden').value(true)
223-
})
224-
.document()
225-
.trigger('visibilitychange')
226-
.get('._toastBar')
227-
.then(($bar) => {
228-
const old = parseFloat($bar.val())
229-
cy.wait(500).then(() => {
230-
expect(parseFloat($bar.val())).to.be.equal(old)
231-
})
232-
})
233-
.document()
234-
.then((doc) => {
235-
cy.stub(doc, 'hidden').value(false)
236-
})
237-
.document()
238-
.trigger('visibilitychange')
239-
.get('._toastBar')
240-
.then(($bar) => {
241-
const old = parseFloat($bar.val())
242-
cy.wait(500).then(() => {
243-
expect(parseFloat($bar.val())).to.be.below(old)
244-
})
245-
})
246-
.get('._toastBtn')
247-
.click()
213+
test('toggles pause and resume on visibilitychange', async ({ page }) => {
214+
const get = async () => parseFloat(await page.locator('._toastBar').getAttribute('value'))
215+
const fire = async (hidden = false) =>
216+
await page.evaluate((value) => {
217+
Object.defineProperty(document, 'hidden', { value, writable: true })
218+
document.dispatchEvent(new Event('visibilitychange'))
219+
}, hidden)
220+
await page.goto('/')
221+
await page.getByTestId('default').click()
222+
await fire(true)
223+
const v0 = await get()
224+
await sleep(100)
225+
const v1 = await get()
226+
expect(v0).toEqual(v1)
227+
await fire(false)
228+
await sleep(100)
229+
const v2 = await get()
230+
expect(v2).toBeLessThan(v1)
248231
})
249-
*/
250232

251233
// Backward compatibility tests
252234

0 commit comments

Comments
 (0)