-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCompTest.test.ts
35 lines (27 loc) · 1.32 KB
/
CompTest.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import '@testing-library/jest-dom'
import {render, fireEvent, screen} from '@testing-library/svelte'
import {it, expect} from 'vitest';
import Comp from './Comp.svelte'
// this test will not cause a second failure
// it('does not happen when sync tests fail', () => {
// render(Comp, {name: 'World'});
// const heading = screen.getByText('Hello world!');
// expect(heading).toBeInTheDocument();
// });
// Note: This is as an async test as we are using `fireEvent`
it('is triggered by async tests failing', async () => {
render(Comp, {name: 'World'});
const button = screen.getByRole('button');
// Using await when firing events is unique to the svelte testing library because
// we have to wait for the next `tick` so that Svelte flushes all pending state changes.
await fireEvent.click(button)
expect(button).toHaveTextContent('Button Clicked');
})
it('sees many buttons', async () => {
const { container } = render(Comp, {name: 'World', values: [], testid: "test2"});
const button = container.querySelector('#test2 button');
// Using await when firing events is unique to the svelte testing library because
// we have to wait for the next `tick` so that Svelte flushes all pending state changes.
await fireEvent.click(button)
expect(button).toHaveTextContent('Button Clicked');
})