Socket
Socket
Sign inDemoInstall

jest-clipboard

Package Overview
Dependencies
1
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    jest-clipboard

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


Version published
Weekly downloads
89
decreased by-8.25%
Maintainers
1
Install size
51.4 kB
Created
Weekly downloads
 

Readme

Source

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

Keywords

FAQs

Last updated on 04 Jun 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc