react-select-event
Advanced tools
Comparing version 5.5.0 to 5.5.1
@@ -78,32 +78,32 @@ 'use strict'; | ||
const select = async (input, optionOrOptions, config = {}) => { | ||
const options = Array.isArray(optionOrOptions) ? optionOrOptions : [optionOrOptions]; | ||
await act$1(async () => { | ||
// Select the items we care about | ||
for (const option of options) { | ||
openMenu(input); | ||
let container; | ||
const options = Array.isArray(optionOrOptions) ? optionOrOptions : [optionOrOptions]; // Select the items we care about | ||
if (typeof config.container === "function") { | ||
// when specified as a function, the container needs to be lazily evaluated, so | ||
// we have to wait for it to be visible: | ||
await dom.waitFor(config.container); | ||
container = config.container(); | ||
} else if (config.container) { | ||
container = config.container; | ||
} else { | ||
container = getReactSelectContainerFromInput(input); | ||
} // only consider visible, interactive elements | ||
for (const option of options) { | ||
await openMenu(input); | ||
let container; | ||
if (typeof config.container === "function") { | ||
// when specified as a function, the container needs to be lazily evaluated, so | ||
// we have to wait for it to be visible: | ||
await dom.waitFor(config.container); | ||
container = config.container(); | ||
} else if (config.container) { | ||
container = config.container; | ||
} else { | ||
container = getReactSelectContainerFromInput(input); | ||
} // only consider visible, interactive elements | ||
const matchingElements = await dom.findAllByText(container, option, { | ||
// @ts-ignore invalid rtl types :'( | ||
ignore: "[aria-live] *,[style*='visibility: hidden']" | ||
}); // When the target option is already selected, the react-select display text | ||
const matchingElements = await dom.findAllByText(container, option, { | ||
// @ts-ignore invalid rtl types :'( | ||
ignore: "[aria-live] *,[style*='visibility: hidden']" | ||
}); | ||
act$1(() => { | ||
// When the target option is already selected, the react-select display text | ||
// will also match the selector. In this case, the actual dropdown element is | ||
// positionned last in the DOM tree. | ||
// positioned last in the DOM tree. | ||
const optionElement = matchingElements[matchingElements.length - 1]; | ||
dom.fireEvent.click(optionElement); | ||
} | ||
}); | ||
}); | ||
} | ||
}; | ||
@@ -110,0 +110,0 @@ |
@@ -74,32 +74,32 @@ import { fireEvent, waitFor, findAllByText, findByText } from '@testing-library/dom'; | ||
const select = async (input, optionOrOptions, config = {}) => { | ||
const options = Array.isArray(optionOrOptions) ? optionOrOptions : [optionOrOptions]; | ||
await act$1(async () => { | ||
// Select the items we care about | ||
for (const option of options) { | ||
openMenu(input); | ||
let container; | ||
const options = Array.isArray(optionOrOptions) ? optionOrOptions : [optionOrOptions]; // Select the items we care about | ||
if (typeof config.container === "function") { | ||
// when specified as a function, the container needs to be lazily evaluated, so | ||
// we have to wait for it to be visible: | ||
await waitFor(config.container); | ||
container = config.container(); | ||
} else if (config.container) { | ||
container = config.container; | ||
} else { | ||
container = getReactSelectContainerFromInput(input); | ||
} // only consider visible, interactive elements | ||
for (const option of options) { | ||
await openMenu(input); | ||
let container; | ||
if (typeof config.container === "function") { | ||
// when specified as a function, the container needs to be lazily evaluated, so | ||
// we have to wait for it to be visible: | ||
await waitFor(config.container); | ||
container = config.container(); | ||
} else if (config.container) { | ||
container = config.container; | ||
} else { | ||
container = getReactSelectContainerFromInput(input); | ||
} // only consider visible, interactive elements | ||
const matchingElements = await findAllByText(container, option, { | ||
// @ts-ignore invalid rtl types :'( | ||
ignore: "[aria-live] *,[style*='visibility: hidden']" | ||
}); // When the target option is already selected, the react-select display text | ||
const matchingElements = await findAllByText(container, option, { | ||
// @ts-ignore invalid rtl types :'( | ||
ignore: "[aria-live] *,[style*='visibility: hidden']" | ||
}); | ||
act$1(() => { | ||
// When the target option is already selected, the react-select display text | ||
// will also match the selector. In this case, the actual dropdown element is | ||
// positionned last in the DOM tree. | ||
// positioned last in the DOM tree. | ||
const optionElement = matchingElements[matchingElements.length - 1]; | ||
fireEvent.click(optionElement); | ||
} | ||
}); | ||
}); | ||
} | ||
}; | ||
@@ -106,0 +106,0 @@ |
{ | ||
"name": "react-select-event", | ||
"version": "5.5.0", | ||
"version": "5.5.1", | ||
"description": "Simulate react-select events for react-testing-library", | ||
@@ -49,5 +49,5 @@ "main": "lib/react-select-event.cjs.js", | ||
"@testing-library/jest-dom": "^5.0.1", | ||
"@testing-library/react": "^12.0.0", | ||
"@testing-library/react": "^12.1.5", | ||
"@types/jest": "^27.0.1", | ||
"@types/react": "^17.0.0", | ||
"@types/react": "^17.0.47", | ||
"@types/react-select": "^5.0.1", | ||
@@ -54,0 +54,0 @@ "jest": "^27.0.4", |
@@ -73,31 +73,32 @@ /** Simulate user events on react-select dropdowns */ | ||
await act(async () => { | ||
// Select the items we care about | ||
for (const option of options) { | ||
openMenu(input); | ||
// Select the items we care about | ||
for (const option of options) { | ||
await openMenu(input); | ||
let container; | ||
if (typeof config.container === "function") { | ||
// when specified as a function, the container needs to be lazily evaluated, so | ||
// we have to wait for it to be visible: | ||
await waitFor(config.container); | ||
container = config.container(); | ||
} else if (config.container) { | ||
container = config.container; | ||
} else { | ||
container = getReactSelectContainerFromInput(input); | ||
} | ||
// only consider visible, interactive elements | ||
const matchingElements = await findAllByText(container, option, { | ||
// @ts-ignore invalid rtl types :'( | ||
ignore: "[aria-live] *,[style*='visibility: hidden']", | ||
}); | ||
let container; | ||
if (typeof config.container === "function") { | ||
// when specified as a function, the container needs to be lazily evaluated, so | ||
// we have to wait for it to be visible: | ||
await waitFor(config.container); | ||
container = config.container(); | ||
} else if (config.container) { | ||
container = config.container; | ||
} else { | ||
container = getReactSelectContainerFromInput(input); | ||
} | ||
// only consider visible, interactive elements | ||
const matchingElements = await findAllByText(container, option, { | ||
// @ts-ignore invalid rtl types :'( | ||
ignore: "[aria-live] *,[style*='visibility: hidden']", | ||
}); | ||
act(() => { | ||
// When the target option is already selected, the react-select display text | ||
// will also match the selector. In this case, the actual dropdown element is | ||
// positionned last in the DOM tree. | ||
// positioned last in the DOM tree. | ||
const optionElement = matchingElements[matchingElements.length - 1]; | ||
fireEvent.click(optionElement); | ||
} | ||
}); | ||
}); | ||
} | ||
}; | ||
@@ -104,0 +105,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
51386