Files
Torsten Dittmann 8640522666 fix: tests
2024-07-17 15:42:03 +02:00

41 lines
1.1 KiB
TypeScript

import { expect, test, vi } from 'vitest';
import { render, fireEvent } from '@testing-library/svelte';
import Copy from '../../../src/lib/mock/copy.test.svelte';
const value = 'This is a test';
test('copy to clipboard function called on click', async () => {
const { getByTestId } = render(Copy, {
value
});
Object.assign(window.navigator, {
clipboard: {
writeText: vi.fn().mockImplementation(() => Promise.resolve())
}
});
const button = getByTestId('copy-content');
await fireEvent.click(button);
expect(window.navigator.clipboard.writeText).toHaveBeenCalledWith('This is a test');
});
test('copy to clipboard function called on enter', async () => {
const { getByTestId } = render(Copy, {
value
});
Object.assign(window.navigator, {
clipboard: {
writeText: vi.fn().mockImplementation(() => Promise.resolve())
}
});
const button = getByTestId('copy-content');
await fireEvent.keyUp(button, {
key: 'Enter'
});
expect(window.navigator.clipboard.writeText).toHaveBeenCalledWith('This is a test');
});