jest-clipboard
TypeScript icon, indicating that this package has built-in type declarations

0.0.11-beta.0 • Public • Published

jest-clipboard

Codacy Badge Coverage Status

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

Further reading

/jest-clipboard/

    Package Sidebar

    Install

    npm i jest-clipboard

    Weekly Downloads

    53

    Version

    0.0.11-beta.0

    License

    ISC

    Unpacked Size

    26.7 kB

    Total Files

    13

    Last publish

    Collaborators

    • marabesi