T
TanStack3y ago
harsh-harlequin

Mocking scrollToIndex with jest

Since the Virtualizer is getting compiled to a function on the build output, jest.spyOn(Virtualizer.prototype, 'scrollToIndex') will not work What would then be the best way to check that scrollToIndex is called with the correct value within a test?
1 Reply
harsh-harlequin
harsh-harlequinOP3y ago
Solution I have got right now: Define this function
export const mockedScrollToIndex = typeof jest === 'undefined'
? noop
: jest.fn()
export const mockedScrollToIndex = typeof jest === 'undefined'
? noop
: jest.fn()
And call it inline within the code whenever I call scrollToIndex

Did you find this page helpful?