Здравствуйте есть компонент
export const Listing = ({
items = [],
hasItems,
isFetching,
observerHandler = noop,
onEndOfListReached,
isBottomLoader,
onLoadImageItems,
onActionsButtonClick = noop,
productViewHandler,
}: Props): React.ReactElement => {
const endOfListRef = useRef(null);
const viewedItems = useRef<Array<number>>([]).current;
const imageLoadTimes = useRef<Array<number>>([]).current;
useEffect(() => {
if (!isFetching && isFunction(observerHandler)) {
observerHandler(endOfListRef.current, onEndOfListReached);
}
}, [endOfListRef, isFetching]);
const deferredCallback = useCallback(debounce(() => {
isFunction(productViewHandler) && productViewHandler(viewedItems);
viewedItems.length = 0;
}, 1000), [productViewHandler]);
{
hasItems
&& items.map(item => (
<ListItem
hasItems
updateItemViewed={(viewedSid: number) => {
if (viewedSid) {
viewedItems.push(viewedSid);
console.log('updateItemViewed', deferredCallback())
deferredCallback();
}
}}
/>
))}
}
тест этого компонента
jest.mock('../../list-item/list-item', () => {
const original = jest.requireActual('../../list-item/list-item');
return {
...original,
__esModule: true,
default: jest.fn(original.default),
};
});
it('should call productViewHandler', async () => {
jest.useFakeTimers();
const spy = jest.fn();
const { container, rerender } = render(<Provider store={createStore(() => ({}))}>
<Listing
items={items}
hasItems
productViewHandler={spy}
/>
</Provider>);
console.log((ListItem as any).mock.calls[0][0].updateItemViewed);
(ListItem as any).mock.calls[0][0].updateItemViewed(1)
jest.runOnlyPendingTimers();
expect(spy).toHaveBeenCalledTimes(1);
});
почему при запуске теста в компоненте пропс productViewHandler приходит как undefined , в тесте я же передаю его