Skip to content

Commit

Permalink
fix: test fails for Svelte5 and happy-dom
Browse files Browse the repository at this point in the history
  • Loading branch information
yanick committed Feb 22, 2024
1 parent d55fbd7 commit 46c2e22
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions src/__tests__/mount.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { describe, expect, test, vi } from 'vitest'
import { VERSION as SVELTE_VERSION } from 'svelte/compiler'

import { act, render, screen } from '..'
import Mounter from './fixtures/Mounter.svelte'
Expand All @@ -7,27 +8,30 @@ const onMounted = vi.fn()
const onDestroyed = vi.fn()
const renderSubject = () => render(Mounter, { onMounted, onDestroyed })

describe('mount and destroy', () => {
test('component is mounted', async () => {
renderSubject()
describe.skipIf(SVELTE_VERSION >= '5' && process.env.VITEST_ENV == 'happy-dom')(
'mount and destroy',
() => {
test('component is mounted', async () => {
renderSubject()

const content = screen.getByRole('button')
const content = screen.getByRole('button')

expect(content).toBeInTheDocument()
await act()
expect(onMounted).toHaveBeenCalledOnce()
})
expect(content).toBeInTheDocument()
await act()
expect(onMounted).toHaveBeenCalledOnce()
})

test('component is destroyed', async () => {
const { unmount } = renderSubject()
test('component is destroyed', async () => {
const { unmount } = renderSubject()

await act()
unmount()
await act()
unmount()

const content = screen.queryByRole('button')
const content = screen.queryByRole('button')

expect(content).not.toBeInTheDocument()
await act()
expect(onDestroyed).toHaveBeenCalledOnce()
})
})
expect(content).not.toBeInTheDocument()
await act()
expect(onDestroyed).toHaveBeenCalledOnce()
})
}
)

0 comments on commit 46c2e22

Please sign in to comment.