From e4688e12a19776567e82250148832ab5439472c9 Mon Sep 17 00:00:00 2001 From: Ruben Verborgh Date: Thu, 24 Mar 2022 17:19:42 +0000 Subject: [PATCH] chore: Simplify test mocks. --- test/unit/util/locking/RedisResourceLocker.test.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/test/unit/util/locking/RedisResourceLocker.test.ts b/test/unit/util/locking/RedisResourceLocker.test.ts index d1735ca4d..0623a8604 100644 --- a/test/unit/util/locking/RedisResourceLocker.test.ts +++ b/test/unit/util/locking/RedisResourceLocker.test.ts @@ -1,5 +1,5 @@ import { EventEmitter } from 'events'; -import * as Redis from 'ioredis'; +import Redis from 'ioredis'; import Redlock from 'redlock'; import type { Lock } from 'redlock'; import * as LogUtil from '../../../../src/logging/LogUtil'; @@ -27,14 +27,11 @@ jest.useFakeTimers(); describe('A RedisResourceLocker', (): void => { let locker: RedisResourceLocker; const identifier = { path: 'http://test.com/foo' }; - let newRedisSpy: jest.SpyInstance; beforeEach(async(): Promise => { jest.clearAllMocks(); redlock.removeAllListeners(); - newRedisSpy = jest.spyOn(Redis, 'default').mockImplementation(jest.fn()); - locker = new RedisResourceLocker([ '6379' ]); }); @@ -180,9 +177,9 @@ describe('A RedisResourceLocker', (): void => { jest.clearAllMocks(); const clientStrings = [ '6379', '127.0.0.1:6378' ]; locker = new RedisResourceLocker(clientStrings); - expect(newRedisSpy).toHaveBeenCalledTimes(2); - expect(newRedisSpy).toHaveBeenCalledWith(6379, undefined); - expect(newRedisSpy).toHaveBeenCalledWith(6378, '127.0.0.1'); + expect(Redis).toHaveBeenCalledTimes(2); + expect(Redis).toHaveBeenCalledWith(6379, undefined); + expect(Redis).toHaveBeenCalledWith(6378, '127.0.0.1'); }); it('errors when invalid string is passed.', async(): Promise => { @@ -191,7 +188,7 @@ describe('A RedisResourceLocker', (): void => { const clientStrings = [ 'noHostOrPort' ]; expect((): any => new RedisResourceLocker(clientStrings)) .toThrow('Invalid data provided to create a Redis client: noHostOrPort'); - expect(newRedisSpy).toHaveBeenCalledTimes(0); + expect(Redis).toHaveBeenCalledTimes(0); }); });