diff --git a/src/commands/del.js b/src/commands/del.js index d3ae8ba37..d3d4e5fc9 100644 --- a/src/commands/del.js +++ b/src/commands/del.js @@ -1,6 +1,10 @@ import { emitNotification } from '../keyspace-notifications' export function del(...keys) { + if (keys.length === 0 || !keys[0]) { + throw new Error("ERR wrong number of arguments for 'del' command") + } + let deleted = 0 keys.forEach(key => { if (this.data.has(key)) { diff --git a/test/integration/commands/__snapshots__/del.js.snap b/test/integration/commands/__snapshots__/del.js.snap new file mode 100644 index 000000000..53ee02af2 --- /dev/null +++ b/test/integration/commands/__snapshots__/del.js.snap @@ -0,0 +1,5 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`del throws if too few arguments 1`] = `"ERR wrong number of arguments for 'del' command"`; + +exports[`delBuffer throws if too few arguments 1`] = `"ERR wrong number of arguments for 'del' command"`; diff --git a/test/integration/commands/del.js b/test/integration/commands/del.js index 3746004ea..d4a6e22a8 100644 --- a/test/integration/commands/del.js +++ b/test/integration/commands/del.js @@ -5,21 +5,34 @@ import { runTwinSuite } from '../../../test-utils' runTwinSuite('del', command => { describe(command, () => { + const redis = new Redis() + + afterAll(() => redis.disconnect()) + it('should delete passed in keys', async () => { - const redis = new Redis() await redis.set('deleteme', 'please') await redis.set('metoo', 'pretty please') expect(await redis[command]('deleteme', 'metoo')).toBe(2) expect(await redis.get('deleteme')).toBe(null) expect(await redis.get('metoo')).toBe(null) - redis.disconnect() }) it('return 0 if nothing is deleted', async () => { - const redis = new Redis() + expect(await redis[command]('deleteme', 'metoo')).toBe(0) + }) + it('return 0 if nothing is deleted', async () => { expect(await redis[command]('deleteme', 'metoo')).toBe(0) - redis.disconnect() + }) + + it('throws if too few arguments', async () => { + expect.assertions(1) + + try { + await redis[command]() + } catch (err) { + expect(err.message).toMatchSnapshot() + } }) }) })