Skip to content

jest-clipboard provides a easy way to test code against the clipboard API.

Notifications You must be signed in to change notification settings

marabesi/jest-clipboard

Repository files navigation

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

About

jest-clipboard provides a easy way to test code against the clipboard API.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published