3.5.89 • Published 10 months ago

@erboladaiorg/et-eos v3.5.89

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.

binaryString.prototype.trimgroupByeslint-pluginjapanesedeep-copyvalidatePromisepropertiesURLSearchParamsframernpmdirectoryflagYAMLscheme-validationbrowserspringObservableses2018electronjsdifffindLastinternal slotcolumncollection.es6toSortedregular-expressionpostcss-pluginbrowserslistES2023configurableObservableassignreal-timeArray.prototype.flatMaptypaniondescriptorsequalprotocol-bufferstyped arrayjsonserviceECMAScript 5localkeyprefixpropertycore-jsdiffrangeerrordefinepipeUint8ClampedArraychaies-shim APIcallbindArray.prototype.findLastlinuxglobal objectcheckdependenciesES8bundlingthreetoolsstructuredClonejsdomsliceES2017reducertoStringTagWeakMapsetImmediatefilterbabeltacitsigintObject.fromEntriesgrouplesssyntaxerrorvariables in csstimelanguagemodulesstatusestreeMapInt8Arrayfpsfunction.lengthroute53loggingemitnodecontainsBigUint64ArrayES2018flatMapreact-hooksReactiveExtensionsflagsrobustrouteeverySystem.globalArrayBuffer.prototype.slicesqscloudformationautoprefixercollectionbytewalkdataViewArray.prototype.includeschromequerycolorUint8Arraysignalsnumbercolumnspolyfillendpointexitauthenticationincludesdynamodblive_.extend$.extenddiroptimistcss variablewhichES2021reducesetPrototypeOfredactmatchAllexecutefullwidthirqcurlassertarrayreact-testing-libraryfastcloneESprotopushenumerableweaksetFloat64ArrayvalueArray.prototype.flateffect-tssomephonelint.envansijestpureReactiveXinstallerdropjoicloneisback-endpoint-freetextoperating-systemwaapipropiteratortypesafeArray.prototype.flattennegativevarregularECMAScript 6dom-testing-librarycloudtrailpluginless mixinsstarternameserverstreamsmoduleES2022ebshttpsbddstreamhandlersnsnopesidepathespreeshebangpicomatchimportconfigtypedarraydeterministicsymboltypescriptECMAScript 2020testerfunctionalttyfile systeminspectnegative zeroBigInt64Arraystrings3terminalgitignorejavascriptredux-toolkitworkerastECMAScript 2023buffersargumenti18nshimenvnodejscall-boundutillinkRxJSsigtermrandomhelperreact-componentpopmotionpatchdeepautoscalingiterationformatyamlextendreadableremoveglobalThisdescriptioncommand-linemovehandlersformattingownvariablesassertionglobales2017superagentproxyvalidatorcallbackdateaccessibilityignoredeepclonefromcoercibleES2019global this valuetraverseObject.definePropertypnpm9utilitiesvpcfast-cloneiamvestdotenvselfcss lessECMAScriptdefinePropertycallboundwgetspeedlengthcomputed-typesMicrosoftreusemixinsajaxdeepcopyworkflownativegraphqlquerystringES2015es-abstractmakevisualemrbabel-coreECMAScript 2018__proto__ECMAScript 2021Streamserrorequalitydomtslibreact animationstylinginputenderkoreanwritablemaptransportworkspace:*fpwidthTypedArrayjshintbinddatastructurelocationlogajvfindLastIndexoutputgetoptArray.prototype.containsramdafsa11ytypeofECMAScript 7simpledbprivate dataslotpositivesortedCSSutilshelpersstyleguideopensslhasOwnelmutil.inspectloggerlesscssIteratorArraydescriptorSymbolfixed-widthmobilefast-deep-copyasterisksacornzodcopyprettymkdirintrinsicwhatwgpinoomitchinesejsxInt16Arrayboundes6ECMAScript 2015classesassertsqueueMicrotaskreduxStreamenvironmentwritecall-bindFunction.prototype.nameTypeBoxUint16Arraysetteruser-streamsinvariantlazytrimLeftvalidationjQueryHyBisymlinklistenerstdditeratecloudsearchgettermetadataRegExp.prototype.flagseast-asian-widthdataviewagenteslintconfigAsyncIteratorconsoleexecserializeclass-validatorUint32ArrayWebSocketscjktrimpromisefunctionmanagerauthgradients css3wafmatchesUnderscorefullsafehookformtypezeroes2015arraybuffer-0objstyled-components@@toStringTagFloat32Arrayfantasy-landhigher-orderbundlertypessyntaxses0sharednested cssbootstrap lessarraysparsesequencefast-deep-cloneruntimecore[[Prototype]]efficientstoragegateway6to5entriesanimationECMAScript 2016toolkittelephonePushsubprocessmapreducequotecompile lesscacheflatless compilerfunctionseslintoptimizerCSSStyleDeclarationrdsdayjsjson-schemareplayoncexhrelbgdprreact poseRFC-6455qsshrinkwrapES3argsspecURLrequirepyyamltypeerroruninstallforEachapimulti-packageprunecommandermergeInt32Arrayhotes5ECMAScript 2019bufferRegExp#flagsfnmatchprivateescapesignaljsgesturesdatapreserve-symlinksasciiregexprecursiveWebSocketcryptconcatarktypeshellsignedObject.valuesexecfileeventDispatchermonorepospinnersextraargvhasOwnPropertyjson-schema-validationwindowsisConcatSpreadableWeakSetlastcss-in-jsfluxObject.getPrototypeOffastredirectstringifyconsumemkdirploadingArrayBuffer#sliceposeawstc39ES5es2016beanstalkloadbalancingimmerrgbminimalpreprocessorsymbolsgetintrinsicimmutablereact-hook-formmockingpasswordgenericses-shimsfetchtestSetTypeScriptfast-copystringifierwarningprocesshashhasaccessorencryptionnpmignoreobjectbootstrap csssameValueZerocomparevaluesreadObject.entriesart256environmentskeyschildpackagesimportexporttrimEndcompilerSymbol.toStringTagforkfigletidleArray.prototype.filterchromiumprototypecensor.gitignoreeslintpluginfastifysetbrowserlistrapidhooksponyfillless.jsinternalec2cryptoconcatMapObject.keysmkdirsmatchreadablestreamtakedependency managerelasticachestatemrusortuploadArray.prototype.findLastIndexsuperstructvarsJSON-Schemashamless cssroutingcommandcloudwatchio-tsgetOwnPropertyDescriptorString.prototype.matchAlloptionasyncECMAScript 2017tsschemaurlmockObjectcharacterhas-ownestranspileparserprogressexit-codebannerprotobufcss nestingclassnamepostcsses8hardlinksdragflattenairbnbcssbinariesjwtinpackage.jsoninstallspinnerviewES6typedlibphonenumbereventEmitterserializerObject.assigncircularfront-endregextoArraytranspilerfastcopyserializationiecolourinferenceweakmapwaitxtermspawnperformantapolloexpressECMAScript 3getPrototypeOfutilityindicatorglobtypedarraysreactcliformfindawesomesaucenamesamazonkinesisArrayBufferperformancetouchcolorsbyteOffsetES2020ES2016settingstostringtagtestingbinhttpECMAScript 2022validtermcurriedglobalsstylesmomentstyle
3.5.89

10 months ago

3.5.88

10 months ago

3.5.87

11 months ago

3.4.87

11 months ago

3.4.86

11 months ago

3.4.85

11 months ago

3.4.84

11 months ago

3.4.83

11 months ago

3.4.82

11 months ago

3.4.81

11 months ago

3.4.80

11 months ago

3.4.79

11 months ago

3.4.78

11 months ago

3.4.77

11 months ago

3.3.77

11 months ago

3.3.76

11 months ago

3.3.75

11 months ago

3.3.74

11 months ago

3.3.73

11 months ago

3.3.72

11 months ago

3.3.71

11 months ago

2.3.71

11 months ago

2.2.71

11 months ago

2.2.70

11 months ago

2.2.69

11 months ago

2.2.68

11 months ago

2.2.67

11 months ago

2.2.66

11 months ago

2.2.65

11 months ago

2.2.64

11 months ago

2.2.63

11 months ago

2.2.62

11 months ago

2.2.61

12 months ago

2.2.60

12 months ago

2.2.59

12 months ago

2.2.58

12 months ago

2.2.57

12 months ago

2.2.56

12 months ago

2.2.55

12 months ago

2.2.54

12 months ago

2.2.53

12 months ago

2.2.52

12 months ago

1.2.52

12 months ago

1.2.51

12 months ago

1.2.50

12 months ago

1.2.49

12 months ago

1.1.49

12 months ago

1.1.48

12 months ago

1.1.47

12 months ago

1.1.46

12 months ago

1.1.45

12 months ago

1.1.44

12 months ago

1.1.43

1 year ago

1.1.42

1 year ago

1.1.41

1 year ago

1.1.40

1 year ago

1.1.39

1 year ago

1.1.38

1 year ago

1.1.37

1 year ago

1.1.36

1 year ago

1.1.35

1 year ago

1.1.34

1 year ago

1.1.33

1 year ago

1.1.32

1 year ago

1.1.31

1 year ago

1.1.30

1 year ago

1.1.29

1 year ago

1.1.28

1 year ago

1.1.27

1 year ago

1.1.26

1 year ago

1.0.26

1 year ago

1.0.25

1 year ago

1.0.24

1 year ago

1.0.23

1 year ago

1.0.22

1 year ago

1.0.21

1 year ago

1.0.20

1 year ago

1.0.19

1 year ago

1.0.18

1 year ago

1.0.17

1 year ago

1.0.16

1 year ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.9

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