import { render, screen } from '@testing-library/svelte'; import userEvent from '@testing-library/user-event'; import { beforeEach, expect, describe, it, vi } from 'vitest'; import MessageInput from '$lib/components/MessageInput.svelte'; const user = userEvent.setup(); const mocks = vi.hoisted(() => ({ sendMessage: vi.fn(), })); describe('MessageInput', async () => { beforeEach(async () => { render(MessageInput, { sendMessage: mocks.sendMessage, }); }); describe('sends a message', async () => { // Skipped as `user-event` can't actually type into a div with // `contenteditable="plaintext-only"` at this time. This capability is // pretty core, though; we'll notice (immediately) if it breaks. // // See . it.skip('with non-empty content', async () => { const input = screen.getByRole('textbox'); await user.type(input, 'a happy surprise'); const send = screen.getByRole('button'); await user.click(send); expect(mocks.sendMessage).toHaveBeenCalledExactlyOnceWith('a happy surprise'); }); it('with empty content', async () => { const send = screen.getByRole('button'); await user.click(send); expect(mocks.sendMessage).toHaveBeenCalledExactlyOnceWith(''); }); }); });