Skip to content

Commit

Permalink
chore: add a onMount test
Browse files Browse the repository at this point in the history
  • Loading branch information
yanick committed Jul 28, 2023
1 parent 66c9f45 commit 801d80c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/__tests__/fixtures/onMount.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div data-testid="target">{message}</div>

<script>
import { onMount } from 'svelte';
let message = "not yet";
onMount( () => {
message = 'nailed it';
});
</script>
18 changes: 18 additions & 0 deletions src/__tests__/onMount.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { expect, test, vi } from 'vitest'

import { render } from '..'
import Comp from './fixtures/onMount.svelte'

vi.mock('svelte', async () => {
const actual = await vi.importActual('svelte')
return {
...actual,
onMount: (await import('svelte/internal')).onMount,
}
})

test('pretty prints the container', () => {
const { getByTestId } = render(Comp)

expect(getByTestId('target').innerHTML).toEqual('nailed it')
})

0 comments on commit 801d80c

Please sign in to comment.