test: improve assertions for spa loading tests

This commit is contained in:
Daniel Roe 2024-12-09 21:40:23 +00:00
parent 5f59f30134
commit 21b6826c1a
No known key found for this signature in database
GPG Key ID: CBC814C393D93268
2 changed files with 8 additions and 6 deletions

View File

@ -25,19 +25,21 @@ await setup({
}) })
describe('spaLoadingTemplateLocation flag is set to `within`', () => { 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<string>('/spa') const html = await $fetch<string>('/spa')
expect(html.replace(/[\n\r]+/g, '')).toContain( expect(html).toContain(
`<div id="__nuxt"><div data-testid="loader">loading...</div></div>`, `<div id="__nuxt"><div data-testid="loader">loading...</div></div>`,
) )
}) })
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 browser = await getBrowser()
const page = await browser.newPage({}) const page = await browser.newPage({})
await page.goto(url('/spa'), { waitUntil: 'domcontentloaded' }) await page.goto(url('/spa'))
const loader = page.getByTestId('loader') const loader = page.getByTestId('loader')
await page.waitForFunction(() => window.useNuxtApp?.() && window.useNuxtApp?.().isHydrating)
expect(await loader.isHidden()).toBeTruthy() expect(await loader.isHidden()).toBeTruthy()
await page.close() await page.close()

View File

@ -24,7 +24,7 @@ describe('spaLoadingTemplateLocation flag is set to `body`', () => {
it('should render spa-loader', async () => { it('should render spa-loader', async () => {
const browser = await getBrowser() const browser = await getBrowser()
const page = await browser.newPage({}) const page = await browser.newPage({})
await page.goto(url('/spa'), { waitUntil: 'domcontentloaded' }) await page.goto(url('/spa'))
const loader = page.getByTestId('loader') const loader = page.getByTestId('loader')
expect(await loader.isVisible()).toBeTruthy() expect(await loader.isVisible()).toBeTruthy()
@ -38,7 +38,7 @@ describe('spaLoadingTemplateLocation flag is set to `body`', () => {
it('should render content without spa-loader', async () => { it('should render content without spa-loader', async () => {
const browser = await getBrowser() const browser = await getBrowser()
const page = await browser.newPage({}) const page = await browser.newPage({})
await page.goto(url('/ssr'), { waitUntil: 'domcontentloaded' }) await page.goto(url('/ssr'))
const loader = page.getByTestId('loader') const loader = page.getByTestId('loader')
expect(await loader.isHidden()).toBeTruthy() expect(await loader.isHidden()).toBeTruthy()