Skip to content

Commit 801d80c

Browse files
committed
chore: add a onMount test
1 parent 66c9f45 commit 801d80c

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/__tests__/fixtures/onMount.svelte

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<div data-testid="target">{message}</div>
2+
3+
<script>
4+
import { onMount } from 'svelte';
5+
6+
let message = "not yet";
7+
8+
onMount( () => {
9+
message = 'nailed it';
10+
});
11+
12+
</script>

src/__tests__/onMount.test.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { expect, test, vi } from 'vitest'
2+
3+
import { render } from '..'
4+
import Comp from './fixtures/onMount.svelte'
5+
6+
vi.mock('svelte', async () => {
7+
const actual = await vi.importActual('svelte')
8+
return {
9+
...actual,
10+
onMount: (await import('svelte/internal')).onMount,
11+
}
12+
})
13+
14+
test('pretty prints the container', () => {
15+
const { getByTestId } = render(Comp)
16+
17+
expect(getByTestId('target').innerHTML).toEqual('nailed it')
18+
})

0 commit comments

Comments
 (0)