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
36
37
|
import { render, screen } from '@testing-library/svelte';
import userEvent from '@testing-library/user-event';
import { beforeEach, expect, test, describe, it, vi } from 'vitest';
import CreateChannelForm from '$lib/components/CreateChannelForm.svelte';
const user = userEvent.setup();
const mocks = vi.hoisted(() => ({
createChannel: vi.fn(),
}));
describe('CreateChannelForm', async () => {
beforeEach(async () => {
render(CreateChannelForm, {
createChannel: mocks.createChannel,
});
});
describe('creates channels', async () => {
it('with a non-empty name', async () => {
const input = screen.getByRole('textbox');
await user.type(input, 'channel name');
const create = screen.getByRole('button');
await user.click(create);
expect(mocks.createChannel).toHaveBeenCalledExactlyOnceWith('channel name');
});
it('with an empty name', async () => {
const create = screen.getByRole('button');
await user.click(create);
expect(mocks.createChannel).toHaveBeenCalledExactlyOnceWith('');
});
});
});
|