-
-
Notifications
You must be signed in to change notification settings - Fork 338
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
Jest TypeError: (0 , _computedWithAutoFillData.computedOffsetXValueWithAutoFillData) is not a function #651
Comments
Hey @andresouza-maple! I'm here to help you with any bugs, questions, or contributions you have for the repository. Let me know how I can assist you! The issue you're encountering with the test breaking on version To resolve the error export function computedOffsetXValueWithAutoFillData(
params: BaseParams<{
rawDataLength: number
value: number
size: number
}>,
) {
"worklet";
const { rawDataLength, value, size, loop, autoFillData } = params;
if (isAutoFillData({ loop, autoFillData })) {
switch (rawDataLength) {
case SINGLE_ITEM:
return value % size;
case DOUBLE_ITEM:
return value % (size * 2);
}
}
return value;
} Ensure that this function is not being referenced before its definition in your code. If the error persists, it might be due to a circular dependency or an import issue. Double-check your import statements and the order of your function definitions to ensure there are no circular dependencies [2]. Additionally, make sure you have the necessary Babel plugin configuration in your module.exports = {
presets: [
...
],
plugins: [
...
'react-native-reanimated/plugin',
],
}; After editing your Babel plugin, try running If these steps do not resolve the issue, you may need to review and possibly update your test logic to ensure it aligns with the new behavior of the carousel component in version |
Answering the bot above, I don't think the changes in the version |
The issue you're encountering is likely related to the new gesture handler API introduced in version To address this, ensure that all your dependencies are compatible with the new version of the carousel. Specifically, verify that Here is an updated version of your test code that includes a check for the new gesture handler API: import React from 'react';
import { Text } from 'react-native';
import Carousel, { CarouselRenderItem } from 'react-native-reanimated-carousel';
import { render, screen } from '@testing-library/react-native';
const data = ['Slide 1', 'Slide 2', 'Slide 3'];
const renderItem: CarouselRenderItem<string> = ({ item }) => (
<Text>{item}</Text>
);
describe('Carousel', () => {
beforeEach(() => {
jest.useFakeTimers();
jest.clearAllMocks();
});
it('renders properly', async () => {
render(<Carousel data={data} renderItem={renderItem} width={200} />);
jest.advanceTimersByTime(2000);
screen.debug();
const card1 = await screen.findByText(data[0]);
expect(card1).toBeDefined();
});
}); If the issue persists, you might need to investigate further into the specific changes introduced in the new version of the carousel and adjust your test setup accordingly. |
Any news on this issue ? I have the same here |
I was able to fix it by adding this in my
|
I have the same issue without Jest. Did I miss something ? |
I tried this, and the error is gone, but I still don't get the Expected Behaviour. When I call <View
style={
{
"flex": 1,
}
}
>
<View
collapsable={false}
onTouchEnd={[Function anonymous]}
onTouchStart={[Function anonymous]}
style={
[
{
"overflow": "hidden",
},
{
"height": "100%",
"width": 200,
},
{},
{
"flexDirection": "row",
},
]
}
/>
</View> |
@andresouza-maple You're right. My fix just makes the error go away, but it doesn't make the carousel component behave correctly. |
I finally resolved the bug on my side with NX 19 and RN 0.73.8 I removed some lines in metro.config.js
I added some plugns in babel.config.js
My package.json for plugins versions:
Hope it helps :) |
Hey, import React, { forwardRef, useEffect, useImperativeHandle } from 'react'
import { FlatList, ListRenderItem } from 'react-native'
import { TCarouselProps } from 'react-native-reanimated-carousel'
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export default forwardRef<
any,
Omit<TCarouselProps, 'onProgressChange'> & {
onProgressChange: (offsetProgress: number, absoluteProgress: number) => void
}
>(function Carousel(
{ renderItem, data, testID, width, height, onProgressChange, defaultIndex = 0 },
ref
) {
useImperativeHandle(ref, () => ({
next: jest.fn(),
prev: jest.fn(),
scrollTo: ({ index }: { index: number }) => {
onProgressChange(0, index)
},
getCurrentIndex: jest.fn(),
}))
useEffect(() => {
if (defaultIndex > 0) {
onProgressChange(0, defaultIndex)
}
}, [defaultIndex, onProgressChange])
return (
<FlatList
ref={ref}
testID={testID}
renderItem={renderItem as unknown as ListRenderItem<unknown>}
data={data}
keyExtractor={(_, index) => index.toString()}
style={{ width, height }}
/>
)
}) |
@mmeissonnier thank you, your mock worked for me. @dohooo is there any chance you can put mock into library, which can be maintained? |
@mmeissonnier the mock worked for me as well. Thanks! |
@mmeissonnier Legend !! thank you |
Describe the bug
My test is broken on version
4.0.0-alpha.12
but it works correctly on version3.5.1
.It is throwing the following error when running it:
My test:
To Reproduce
Steps to reproduce the behavior:
4.0.0-alpha.12
;Expected behavior
The carousel should render the slides in the DOM and the test should pass.
What I expect to see when I run
screen.debug()
:Versions:
Smartphone (please complete the following information):
Additional context
I know version
4.0.0
is still in Alpha, but I thought you wanted to know about this issue before the release.The text was updated successfully, but these errors were encountered: