исправленная функция «не функция» в модульном тесте - PullRequest
1 голос
/ 08 ноября 2019

Я пытаюсь смоделировать debounce, чтобы я мог проверить отклоненную функцию в моих модульных тестах, но она говорит мне функцию is not a function

Ошибка:

TypeError: (0 , _usersDialog.debounceUpdateSearchText) is not a function

Функция:

export const debounceUpdateSearchText = debounce(
  (updateText, searchString) => {
    if (searchString === '' || searchString.length === 1) {
      updateText(' ');
    }
    updateText(searchString);
  },
  500
);

тестовый код:

// earlier in the file
import debounce from 'lodash/debounce';
jest.mock('lodash/debounce');
// test
it('updates the search text', () => {
      // jest.useFakeTimers();
      debounce.mockImplementation(fn => fn);
      const updateText = jest.fn();
      // call function
      debounceUpdateSearchText(updateText, 'fuego');

      // jest.advanceTimersByTime(501);
      expect(props.updateText).toHaveBeenCalledWith('fuego');
    });

1 Ответ

0 голосов
/ 08 ноября 2019

Оказалось, что мой дебаг-макет был отключен простым прикосновением, рабочий код:

import debounce from 'lodash/debounce';
jest.mock('lodash/debounce', () => jest.fn(fn => fn));
...