-
-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: TypeError: Cannot read properties of undefined (reading 'map') in AutoHeight #1009
Comments
@suraj776 have you created the necessary mocks? See: |
@davidjerleke yes, i do have all the mocks. Still getting error and it is from AutoHeight plugin.If i remove plugin, test cases do work. |
@davidjerleke actually here, here you need to add null check before map. |
@suraj776 no here, because we're mapping the - const selectedIndexes = slideRegistry[emblaApi.selectedScrollSnap()]
+ const selectedIndexes = slideRegistry[emblaApi.selectedScrollSnap()] || [] But that might lead to errors in other places. Like the function that depends on the function setContainerHeight(): void {
emblaApi.containerNode().style.height = `${highestInView()}px`
} Can you create a CodeSandbox that reproduces the problem? If you do I can solve it faster. |
Please check this sandbox code. run command
|
@suraj776 thanks. That helps. So this solves it: function highestInView(): number | null {
const { slideRegistry } = emblaApi.internalEngine()
const selectedIndexes = slideRegistry[emblaApi.selectedScrollSnap()]
if (!selectedIndexes) return null // Bail here if no selectedIndexes are found
return selectedIndexes
.map((index) => slideHeights[index])
.reduce((a, b) => Math.max(a, b), 0)
}
function setContainerHeight(): void {
const height = highestInView()
if (height === null) return // Bail here if we don't have any height to apply
emblaApi.containerNode().style.height = `${highestInView()}px`
} Feel free to create a PR with the solution above. Best, |
@davidjerleke, Thanks for quick support. |
[Bug]: TypeError: Cannot read properties of undefined (reading 'map') in AutoHeight
Which variants of Embla Carousel are you using?
Steps to reproduce
I'm trying to create a integration test using React Testing library.
Error:- I'm getting.
detail: TypeError: Cannot read properties of undefined (reading 'map')
at map (/node_modules/embla-carousel-auto-height/src/components/AutoHeight.ts:51:8)
at highestInView (/node_modules/embla-carousel-auto-height/src/components/AutoHeight.ts:56:48)
Expected Behavior
It should be mockable when applying mocks.
Additional Context
I have also tried...
What browsers are you seeing the problem on?
All browsers
Version
^8.2.0
CodeSandbox
No response
Before submitting
The text was updated successfully, but these errors were encountered: