From 21b6826c1a4343146c6864d67b92276818e66c43 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Mon, 9 Dec 2024 21:40:23 +0000 Subject: [PATCH] test: improve assertions for spa loading tests --- test/spa-loader/spa-preloader-outside-disabled.test.ts | 10 ++++++---- test/spa-loader/spa-preloader-outside-enabled.test.ts | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/test/spa-loader/spa-preloader-outside-disabled.test.ts b/test/spa-loader/spa-preloader-outside-disabled.test.ts index 1a6e1efbf5..5c794b627e 100644 --- a/test/spa-loader/spa-preloader-outside-disabled.test.ts +++ b/test/spa-loader/spa-preloader-outside-disabled.test.ts @@ -25,19 +25,21 @@ await setup({ }) describe('spaLoadingTemplateLocation flag is set to `within`', () => { - it('shoul be render loader inside appTag', async () => { + it('should render loader inside appTag', async () => { const html = await $fetch('/spa') - expect(html.replace(/[\n\r]+/g, '')).toContain( + expect(html).toContain( `
loading...
`, ) }) - it.skipIf(isDev)('spa-loader does not appear while the app is mounting', async () => { + it('spa-loader does not appear while the app is mounting', async () => { const browser = await getBrowser() const page = await browser.newPage({}) - await page.goto(url('/spa'), { waitUntil: 'domcontentloaded' }) + await page.goto(url('/spa')) const loader = page.getByTestId('loader') + + await page.waitForFunction(() => window.useNuxtApp?.() && window.useNuxtApp?.().isHydrating) expect(await loader.isHidden()).toBeTruthy() await page.close() diff --git a/test/spa-loader/spa-preloader-outside-enabled.test.ts b/test/spa-loader/spa-preloader-outside-enabled.test.ts index ac894f2d13..f8313b1eec 100644 --- a/test/spa-loader/spa-preloader-outside-enabled.test.ts +++ b/test/spa-loader/spa-preloader-outside-enabled.test.ts @@ -24,7 +24,7 @@ describe('spaLoadingTemplateLocation flag is set to `body`', () => { it('should render spa-loader', async () => { const browser = await getBrowser() const page = await browser.newPage({}) - await page.goto(url('/spa'), { waitUntil: 'domcontentloaded' }) + await page.goto(url('/spa')) const loader = page.getByTestId('loader') expect(await loader.isVisible()).toBeTruthy() @@ -38,7 +38,7 @@ describe('spaLoadingTemplateLocation flag is set to `body`', () => { it('should render content without spa-loader', async () => { const browser = await getBrowser() const page = await browser.newPage({}) - await page.goto(url('/ssr'), { waitUntil: 'domcontentloaded' }) + await page.goto(url('/ssr')) const loader = page.getByTestId('loader') expect(await loader.isHidden()).toBeTruthy()