Mocking @wordpress/data `useSelect` hook


I am trying to use useSelect. I want to test

  1. The string pass select is video-store
  2. I am actually calling getVideoCollection

However I am getting following error. TypeError: useSelect.mockImplementation is not a function

I am not sure what I am doing wrong here ?

// Component

export function Videos(props) {
    const {data} = useSelect(select => {
        return select('video-store').getVideoCollection();
    }, []);

    return (<Videos data={data}/>);
// spec file
import { Videos } from ‘../Videos’;
import { mount, shallow } from 'enzyme';
Import { useSelect } 'WPBeginner - WordPress Tutorials/data'

jest.mock('WPBeginner - WordPress Tutorials/data/src/components/use-select', () => {
    const mock = jest.fn()
    return mock 

describe('Videos', () => {
    it('should get Videos’, () => {
        useSelect.mockImplementation(() => ({
          data: []

I am not sure why console.log is not showing mockImplementation

console.log output for useSelect

      addMatchers: [Function: addMatchers],
      advanceTimersByTime: [Function: advanceTimersByTime],
      advanceTimersToNextTimer: [Function: advanceTimersToNextTimer],
      autoMockOff: [Function: disableAutomock],
      autoMockOn: [Function: enableAutomock],
      clearAllMocks: [Function: clearAllMocks],
      clearAllTimers: [Function: clearAllTimers],
      createMockFromModule: [Function: createMockFromModule],
      deepUnmock: [Function: deepUnmock],
      disableAutomock: [Function: disableAutomock],
      doMock: [Function: mock],
      dontMock: [Function: unmock],
      enableAutomock: [Function: enableAutomock],
      fn: [Function: bound fn],
      genMockFromModule: [Function: genMockFromModule],
      getRealSystemTime: [Function: getRealSystemTime],
      getTimerCount: [Function: getTimerCount],
      isMockFunction: [Function: isMockFunction],
      isolateModules: [Function: isolateModules],
      mock: [Function: mock],
      requireActual: [Function: bound requireActual],
      requireMock: [Function: bound requireMock],
      resetAllMocks: [Function: resetAllMocks],
      resetModuleRegistry: [Function: resetModules],
      resetModules: [Function: resetModules],
      restoreAllMocks: [Function: restoreAllMocks],
      retryTimes: [Function: retryTimes],
      runAllImmediates: [Function: runAllImmediates],
      runAllTicks: [Function: runAllTicks],
      runAllTimers: [Function: runAllTimers],
      runOnlyPendingTimers: [Function: runOnlyPendingTimers],
      runTimersToTime: [Function: runTimersToTime],
      setMock: [Function: setMock],
      setSystemTime: [Function: setSystemTime],
      setTimeout: [Function: setTimeout],
      spyOn: [Function: bound spyOn],
      unmock: [Function: unmock],
      useFakeTimers: [Function: useFakeTimers],
      useRealTimers: [Function: useRealTimers]

, , Kristina Ferriera 3 months 0 Answers 41 views 0

Leave an answer