Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Cannot test with react-testing-library #661
Comments
|
Note that in the library tests, which use enzyme, the focus event is fired on the slider component itself, not the handle, which is what the getByRole returns, I believe. Might try adjusting based on that. I messed around with some basic tests a bit but couldn't get it to work and have more pressing things to do, but wanted to point that out just in case it was helpful. |
Description
Hi, I've been working on testing a component which contains multiple
<Range>components with@react-testing-libraryand are having issues attempting to programmatically changing the value of the slider. Specifically I cannot replicate a focus and keydown user event.Code
This is what my code looks like:
These are the results of the
console.log()calls:Slider after focus: <div aria-disabled="false" aria-valuemax="60" aria-valuemin="0.5" aria-valuenow="30.5" class="rc-slider-handle rc-slider-handle-2" role="slider" style="left: 50.42016806722689%; transform: translateX(-50%);" tabindex="0" /> Slider after KeyDown: <div aria-disabled="false" aria-valuemax="60" aria-valuemin="0.5" aria-valuenow="30.5" class="rc-slider-handle rc-slider-handle-2" role="slider" style="left: 50.42016806722689%; transform: translateX(-50%);" tabindex="0" />As you can see, the
valuenowis the same before and after thekeyDownevent. Also I noticed therc-slider-handle-draggingclass is not present.The code below shows how I am currently rendering the
<Range>component:NOTE 1:
The Range's
onChangehandler is triggered, but the event contains the same exact values the<Range>currently has which is :[0.5, 30.5, 60](There's no change in the actual values).NOTE 2:
The class
rc-slider-handle-draggingis present in the first slider even though I never set it myself. If I try to fire akeyDownevent it does not work either.Update 1:
Looking at both the
container.baseElementand the actual Range, they both have aclientHeightandclientWidthof0. Not sure if that might be causing the issues.Environment
rc-slider: "9.2.4"@types/rc-slider: "^8.6.5"@testing-library/react: "^9.5.0"@testing-library/jest-dom: "^4.2.4"