4.16.107 • Published 10 months ago

@erboladaiorg/tenetur-magni-ab v4.16.107

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

npm version Build Status Coverage report code style: prettier

Install

npm install --save-dev react-select-event

Import react-select-event in your unit tests:

import selectEvent from "react-select-event";
// or
const selectEvent = require("react-select-event");

Supported versions of react-select

This library is tested against all versions of react-select starting from 4.0.0.

API

Every helper exported by react-select-event takes a handle on the react-select input field as its first argument. For instance, this can be: getByLabelText("Your label name").

select(input: HTMLElement, optionOrOptions: Matcher | Array<Matcher>, config?: object): Promise<void>

The optionOrOptions parameter can be any valid dom-testing-library TextMatch object (eg. string, regex, function, number).

Select one or more values in a react-select dropdown.

const { getByRole, getByLabelText } = render(
  <form role="form">
    <label htmlFor="food">Food</label>
    <Select options={OPTIONS} name="food" inputId="food" isMulti />
  </form>
);
expect(getByRole("form")).toHaveFormValues({ food: "" });

await selectEvent.select(getByLabelText("Food"), ["Strawberry", "Mango"]);
expect(getByRole("form")).toHaveFormValues({ food: ["strawberry", "mango"] });

await selectEvent.select(getByLabelText("Food"), "Chocolate");
expect(getByRole("form")).toHaveFormValues({
  food: ["strawberry", "mango", "chocolate"],
});

This also works for async selects:

const { getByRole, getByLabelText } = render(
  <form role="form">
    <label htmlFor="food">Food</label>
    <Async
      options={[]}
      loadOptions={fetchTheOptions}
      name="food"
      inputId="food"
      isMulti
    />
  </form>
);
expect(getByRole("form")).toHaveFormValues({ food: "" });

// start typing to trigger the `loadOptions`
userEvent.type(getByLabelText("Food"), "Choc");
await selectEvent.select(getByLabelText("Food"), "Chocolate");
expect(getByRole("form")).toHaveFormValues({
  food: ["chocolate"],
});

select also accepts an optional config parameter. config.container can be used to specify a custom container to use when the react-select dropdown is rendered in a portal using menuPortalTarget:

const { getByRole, getByLabelText } = render(
  <form role="form">
    <label htmlFor="food">Food</label>
    <Select
      options={OPTIONS}
      name="food"
      inputId="food"
      isMulti
      menuPortalTarget={document.body}
    />
  </form>
);
await selectEvent.select(getByLabelText("Food"), ["Strawberry", "Mango"], {
  container: document.body,
});
expect(getByRole("form")).toHaveFormValues({ food: ["strawberry", "mango"] });

The container can also be passed in as a function if it needs to be lazily evaluated:

const { getByRole, getByLabelText } = render(
  <form role="form">
    <label htmlFor="food">Food</label>
    <Select
      options={OPTIONS}
      name="food"
      inputId="food"
      isMulti
      menuPortalTarget={document.body}
    />
  </form>
);
await selectEvent.select(getByLabelText("Food"), ["Strawberry", "Mango"], {
  container: () => document.body.querySelector("[class$=-menu]"),
});
expect(getByRole("form")).toHaveFormValues({ food: ["strawberry", "mango"] });

create(input: HTMLElement, option: string, config?: object): Promise<void> }

Creates and selects a new item. Only applicable to react-select Creatable elements.

const { getByRole, getByLabelText } = render(
  <form role="form">
    <label htmlFor="food">Food</label>
    <Creatable options={OPTIONS} name="food" inputId="food" />
  </form>
);
expect(getByRole("form")).toHaveFormValues({ food: "" });
await selectEvent.create(getByLabelText("Food"), "papaya");
expect(getByRole("form")).toHaveFormValues({ food: "papaya" });

create take an optional config parameter:

clearFirst(input: HTMLElement): Promise<void>

Clears the first value in the dropdown.

const { getByRole, getByLabelText } = render(
  <form role="form">
    <label htmlFor="food">Food</label>
    <Creatable
      defaultValue={OPTIONS[0]}
      options={OPTIONS}
      name="food"
      inputId="food"
      isMulti
    />
  </form>
);
expect(getByRole("form")).toHaveFormValues({ food: "chocolate" });
await selectEvent.clearFirst(getByLabelText("Food"));
expect(getByRole("form")).toHaveFormValues({ food: "" });

clearAll(input: HTMLElement): Promise<void>

Clears all values in the dropdown.

const { getByRole, getByLabelText } = render(
  <form role="form">
    <label htmlFor="food">Food</label>
    <Creatable
      defaultValue={[OPTIONS[0], OPTIONS[1], OPTIONS[2]]}
      options={OPTIONS}
      name="food"
      inputId="food"
      isMulti
    />
  </form>
);
expect(getByRole("form")).toHaveFormValues({
  food: ["chocolate", "vanilla", "strawberry"],
});
await selectEvent.clearAll(getByLabelText("Food"));
expect(getByRole("form")).toHaveFormValues({ food: "" });

openMenu(input: HTMLElement): void

Opens the select dropdown menu by focusing the input and simulating a down arrow keypress.

const { getByLabelText, queryByText } = render(
  <form>
    <label htmlFor="food">Food</label>
    <Select options={[{ label: "Pizza", value: 1 }]} inputId="food" />
  </form>
);
expect(queryByText("Pizza")).toBeNull();
selectEvent.openMenu(getByLabelText("Food"));
expect(getByText("Pizza")).toBeInTheDocument();

Credits

All the credit goes to Daniel and his StackOverflow answer: https://stackoverflow.com/a/56085734.

typesvarssequencecoveragetrimrouteoutputtouchhooksaccessibilityrfc4122stableReflect.getPrototypeOfpromisesinspectwalkmkdirptapcoercibleelbflatenderclass-validatorrmPushlook-upsesoptionspinnersesxtermES7modulesruntimepackage.jsonfindLastlooktoolkitloadingmkdirsreact animationcall-bindgesturesfullthroattyped arrayapiReactiveXwaapimobilequoteaccessormapreducedependencieschromiumES2020elasticachewidthtypeerrorgroupByponyfilleventDispatcherbreakprotocol-bufferscharactersargumentses8listenersmoduleroutingRFC-6455execdefaultjsdomArray.prototype.includestddprogressloadbalancingMaplastintrinsicRegExp.prototype.flagses2015cloudformationoptimistnativeURLflagsObject.definePropertyhasOwnPropertyrobusterrorfastcopyreuseespreecall-boundtypedidentifiersfile cacheStyleSheetzodRegExp#flagsflatMapObject.assignconfigcommandereventsuuidastcloneagentredactbddredux-toolkitJSON-SchemautilitiesiamdeepcopyWebSocketsyntaxSetwgethttpdatamrutextreact-hook-formstatelessdirbrowseriteratedayjsdeletereduxArrayrapides2016clitypescriptshebangES2021yamlpushfileregularbundlerObject.isistanbultrimEndtoStringTagfromcurlqueueMicrotaskhelperscodesjshintmake dirvaluesio-tsbyteLengthsettercompileremitArrayBuffer.prototype.slicemetadatadefinebrowserslistcirculartapeprettydateconvertES2016entriesgetarktypehashfastequaltypaniontypesafekeysInt32ArraySymbol.toStringTag0testerebsfindupcolorsmulti-packagesymboltoSortedsomePromiseremoveES2018ESfilterexpressionyupimmutablereact-hooksdeeparraysextendtestwhatwgUint16Arrayconcurrencyavashimcode pointscallbindsimpledboffsetrmdirinvariantspringStream__proto__importECMAScript 5censorArrayBuffer#slicearraybufferwalkingjavascripttostringtagObjectviewtimeswfdeterministicfast-copyes7environmentjsxwritablestoragegatewayboundregular expressionstypedarrayprefixidtrimRightinstallerdotenvutilenvvisualES2022streamsgenericsArray.prototype.findLastIndexassigntslibparsestarterreducersearchflattenvariablesobjecteast-asian-widthvalue
@dramaorg/esse-praesentium-eligendi@dramaorg/quae-dolore-nostrum@erboladaiorg/ad-exercitationem-ducimus@erboladaiorg/adipisci-repellendus-corporis@erboladaiorg/asperiores-earum-quaerat@erboladaiorg/asperiores-fuga-sint@erboladaiorg/asperiores-nam-adipisci@erboladaiorg/autem-dolores-ipsam@erboladaiorg/cum-commodi-consequatur@erboladaiorg/cupiditate-consectetur-porro@erboladaiorg/cupiditate-pariatur-optio@erboladaiorg/distinctio-tempora-quis@erboladaiorg/error-atque-ea@erboladaiorg/esse-ipsa-numquam@erboladaiorg/ex-hic-molestias@erboladaiorg/explicabo-eius-adipisci@erboladaiorg/fugiat-nobis-repellendus@erboladaiorg/laboriosam-inventore-natus@erboladaiorg/molestiae-voluptatibus-perferendis@erboladaiorg/molestias-nulla-dolor@erboladaiorg/nisi-culpa-cum@erboladaiorg/officia-illum-aperiam@erboladaiorg/perspiciatis-magni-ut@erboladaiorg/quae-in-veniam@erboladaiorg/quaerat-mollitia-adipisci@erboladaiorg/quibusdam-itaque-tempora@erboladaiorg/quod-explicabo-neque@erboladaiorg/sint-deleniti-dolorem@erboladaiorg/sit-nesciunt-amet@erboladaiorg/tenetur-architecto-dolore@erboladaiorg/ut-dignissimos-laborum@erboladaiorg/velit-fugit-harum@juigorg/nisi-molestiae-ut@juigorg/sit-nam-neque@kollorg/dicta-itaque-nemo@kollorg/nihil-veniam-deserunt@swenkerorg/modi-dolorum-provident@swenkerorg/nulla-voluptates-voluptates@zitterorg/aspernatur-pariatur-occaecati@zitterorg/eum-veritatis-placeat@zitterorg/illum-perferendis-consecteturanalsorhost-simple-bscorcojs-qrcodecorcojs-qrcode-logodable-effectfiran-loggingsimple-assi-animationsimple-prompts-web3
4.15.99

11 months ago

3.9.59

1 year ago

3.9.57

1 year ago

3.9.58

1 year ago

3.9.56

1 year ago

3.11.68

12 months ago

3.11.67

12 months ago

3.11.69

12 months ago

1.4.20

1 year ago

1.4.22

1 year ago

1.4.21

1 year ago

1.4.24

1 year ago

1.4.23

1 year ago

4.15.96

11 months ago

4.15.98

11 months ago

4.15.97

11 months ago

3.11.71

12 months ago

3.11.70

12 months ago

3.9.62

12 months ago

3.9.60

1 year ago

2.8.49

1 year ago

3.9.61

12 months ago

2.8.48

1 year ago

2.8.47

1 year ago

2.8.52

1 year ago

2.8.51

1 year ago

2.8.50

1 year ago

2.8.54

1 year ago

2.8.53

1 year ago

1.1.16

1 year ago

1.1.15

1 year ago

1.1.14

1 year ago

1.1.13

1 year ago

1.1.18

1 year ago

1.1.17

1 year ago

4.15.100

11 months ago

1.6.31

1 year ago

1.6.33

1 year ago

1.6.32

1 year ago

3.13.74

12 months ago

1.6.35

1 year ago

3.13.75

12 months ago

1.6.34

1 year ago

4.14.92

11 months ago

1.6.37

1 year ago

4.14.93

11 months ago

1.6.36

1 year ago

4.14.90

11 months ago

1.6.39

1 year ago

4.14.91

11 months ago

1.6.38

1 year ago

4.14.96

11 months ago

4.14.94

11 months ago

1.4.19

1 year ago

4.14.95

11 months ago

1.4.18

1 year ago

4.14.89

11 months ago

4.14.87

11 months ago

4.14.88

11 months ago

4.16.106

10 months ago

4.16.107

10 months ago

1.5.30

1 year ago

3.12.72

12 months ago

3.12.71

12 months ago

1.5.31

1 year ago

3.12.74

12 months ago

3.12.73

12 months ago

4.16.100

11 months ago

4.16.101

11 months ago

4.16.102

11 months ago

4.16.103

10 months ago

1.3.18

1 year ago

4.16.104

10 months ago

4.16.105

10 months ago

3.8.56

1 year ago

3.8.54

1 year ago

3.8.55

1 year ago

3.10.64

12 months ago

3.10.65

12 months ago

3.10.62

12 months ago

3.10.63

12 months ago

3.10.66

12 months ago

3.10.67

12 months ago

1.2.18

1 year ago

3.14.77

11 months ago

3.14.78

11 months ago

3.14.79

11 months ago

3.14.75

12 months ago

3.14.76

11 months ago

1.7.39

1 year ago

2.7.47

1 year ago

3.14.80

11 months ago

1.7.40

1 year ago

3.14.81

11 months ago

1.7.41

1 year ago

3.14.82

11 months ago

1.7.42

1 year ago

3.14.83

11 months ago

1.7.43

1 year ago

3.14.84

11 months ago

1.7.44

1 year ago

3.14.85

11 months ago

1.7.45

1 year ago

3.14.86

11 months ago

1.7.46

1 year ago

3.14.87

11 months ago

1.7.47

1 year ago

1.5.25

1 year ago

1.5.24

1 year ago

1.5.27

1 year ago

1.5.26

1 year ago

1.5.29

1 year ago

1.5.28

1 year ago

1.0.13

1 year ago

1.0.9

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.12

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago