blob: ab77c11bffa152b9d0fe1cd9fce38bf00cfd2c73 (
plain)
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
|
import { render, screen } from '@testing-library/svelte';
import userEvent from '@testing-library/user-event';
import { beforeEach, expect, test, describe, it, vi } from 'vitest';
import LogIn from '$lib/components/LogIn.svelte';
const user = userEvent.setup();
const mocks = vi.hoisted(() => ({
logIn: vi.fn()
}));
describe('LogIn', async () => {
beforeEach(async () => {
render(LogIn, {
logIn: mocks.logIn
});
});
it('sends a login request', async () => {
const username = screen.getByLabelText('username');
await user.type(username, 'my username');
const password = screen.getByLabelText('password');
await user.type(password, 'my very creative and long password');
const signIn = screen.getByRole('button');
await user.click(signIn);
expect(mocks.logIn).toHaveBeenCalledExactlyOnceWith(
'my username',
'my very creative and long password'
);
});
});
|