jest-clipboard
v0.0.11-beta.0
Published
jest-clipboard provides a easy way to test code against the clipboard API.
Downloads
510
Readme
jest-clipboard
jest-clipboard provides a easy way to test code against the clipboard API.
Usage
// your implementation
import {readTextFromClipboard} from "./clipboard";
const thisFunctionWritesToClipboard = async () => {
await navigator.clipboard.writeText('text from clipboard');
};
// your implementation to read from the clipboard
const thisFunctionReadContentFromClipboard = async (): Promise<ClipboardItems> => {
return navigator.clipboard.read();
}
describe('Clipboard', () => {
beforeEach(() => {
setUpClipboard();
});
afterEach(() => {
tearDownClipboard();
});
it('should use text from clipboard', async () => {
await writeTextToClipboard('I want this to be in the transfer area');
expect(global.navigator.clipboard.writeText).toHaveBeenCalledWith('text from clipboard');
// or
expect(await readTextFromClipboard()).toEqual('I want this to be in the transfer area');
});
});
Projects using jest-clipboard
- json-tool uses jest-clipboard to setup a scenario for tests have a look at this file