Mocking Redis Get / Set в конструкторе с Jest - PullRequest
0 голосов
/ 21 июня 2019

Я пишу модульный тест с jest, и мне нужно смоделировать Redis Get / Set в конструкторе, но у меня проблема с переданным аргументом uti.promisify.

Пытался смоделировать redis-mock, импортировать как RedisClient, вставить в конструктор с помощью Get / Set.

Здесь тест

import RedisClient from 'redis-mock';
import { promisify } from 'util';

it(should call testService class constructor', () => {

   const testServiceProxy = new testServiceProxy({ RedisClient });

 expect(testServiceProxy._redis).toBe(RedisClient);
 expect(testServiceProxy._redisGetAsync).toBe(testServiceProxy._redis.get).bind(testServiceProxy._redis);
 expect(testServiceProxy._redisGetAsync).toBe(testServiceProxy._redis.set).bind(testServiceProxy._redis);
});

Рабочий конструктор

constructor({ RedisClient }) {

        this._redis = RedisClient;
        this._redisGetAsync = promisify(this._redis.get).bind(this._redis);
        this._redisSetAsync = promisify(this._redis.set).bind(this._redis);
    }

После запуска jest TestService.test.js

Сообщение об ошибке в рабочем конструкторе : «Оригинальный» аргумент должен иметь тип функции

...