Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-select-event

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-select-event

Simulate react-select events for react-testing-library

  • 4.1.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is react-select-event?

The react-select-event package is a utility for testing React Select components with ease. It provides a set of functions to simulate user interactions with React Select components, making it easier to write tests for applications that use these components.

What are react-select-event's main functionalities?

selectOption

The `selectOption` function allows you to simulate selecting an option from a React Select component. This is useful for testing scenarios where you need to verify that the correct option is selected based on user interaction.

const { select } = require('react-select-event');
const { render, screen } = require('@testing-library/react');
const React = require('react');
const Select = require('react-select');

const options = [
  { value: 'chocolate', label: 'Chocolate' },
  { value: 'strawberry', label: 'Strawberry' },
  { value: 'vanilla', label: 'Vanilla' }
];

render(<Select options={options} />);
await select(screen.getByLabelText('Select...'), 'Chocolate');

clearFirst

The `clearFirst` function allows you to simulate clearing the first selected option in a multi-select React Select component. This is useful for testing scenarios where you need to verify that the correct options are cleared based on user interaction.

const { clearFirst } = require('react-select-event');
const { render, screen } = require('@testing-library/react');
const React = require('react');
const Select = require('react-select');

const options = [
  { value: 'chocolate', label: 'Chocolate' },
  { value: 'strawberry', label: 'Strawberry' },
  { value: 'vanilla', label: 'Vanilla' }
];

render(<Select options={options} isMulti />);
await select(screen.getByLabelText('Select...'), 'Chocolate');
await select(screen.getByLabelText('Select...'), 'Vanilla');
await clearFirst(screen.getByLabelText('Select...'));

createNewOption

The `createNewOption` function allows you to simulate creating a new option in a Creatable React Select component. This is useful for testing scenarios where you need to verify that new options can be added based on user interaction.

const { createNewOption } = require('react-select-event');
const { render, screen } = require('@testing-library/react');
const React = require('react');
const CreatableSelect = require('react-select/creatable');

const options = [
  { value: 'chocolate', label: 'Chocolate' },
  { value: 'strawberry', label: 'Strawberry' },
  { value: 'vanilla', label: 'Vanilla' }
];

render(<CreatableSelect options={options} />);
await createNewOption(screen.getByLabelText('Select...'), 'Mint');

Other packages similar to react-select-event

Keywords

FAQs

Package last updated on 08 Jan 2020

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc