diff --git a/node/src/BaseClient.ts b/node/src/BaseClient.ts index 3b0debee02..ddd55730c3 100644 --- a/node/src/BaseClient.ts +++ b/node/src/BaseClient.ts @@ -1058,8 +1058,8 @@ export class BaseClient { } /** - * Sets the list element at index to element. - * The index is zero-based, so 0 means the first element,1 the second element and so on. + * Sets the list element at `index` to `element`. + * The index is zero-based, so 0 means the first element, 1 the second element and so on. * Negative indices can be used to designate elements starting at the tail of * the list. Here, -1 means the last element, -2 means the penultimate and so forth. * diff --git a/node/src/Transaction.ts b/node/src/Transaction.ts index 9975f480a6..4210d5c714 100644 --- a/node/src/Transaction.ts +++ b/node/src/Transaction.ts @@ -583,8 +583,8 @@ export class BaseTransaction> { } /** - * Sets the list element at index to element. - * The index is zero-based, so 0 means the first element,1 the second element and so on. + * Sets the list element at `index` to `element`. + * The index is zero-based, so 0 means the first element, 1 the second element and so on. * Negative indices can be used to designate elements starting at the tail of * the list. Here, -1 means the last element, -2 means the penultimate and so forth. * diff --git a/node/tests/SharedTests.ts b/node/tests/SharedTests.ts index 7f54b579d6..920bfd0767 100644 --- a/node/tests/SharedTests.ts +++ b/node/tests/SharedTests.ts @@ -874,11 +874,11 @@ export function runBaseTests(config: { ); it.each([ProtocolVersion.RESP2, ProtocolVersion.RESP3])( - `lset with nonexisting key`, + `lset test_%p`, async (protocol) => { await runTest(async (client: BaseClient) => { const key = "test_key"; - const non_existing_key = "nonexisting"; + const nonExistingKey = "nonexisting"; const index = 0; const oobIndex = 10; const negativeIndex = -1; @@ -890,7 +890,7 @@ export function runBaseTests(config: { // key does not exist try { expect( - await client.lset(non_existing_key, index, element), + await client.lset(nonExistingKey, index, element), ).toThrow(); } catch (e) { expect((e as Error).message).toMatch( @@ -910,18 +910,32 @@ export function runBaseTests(config: { } // assert lset result - expect(await client.lset(key, index, element)).toEqual("OK"); + checkSimple(await client.lset(key, index, element)).toEqual( + "OK", + ); checkSimple(await client.lrange(key, 0, negativeIndex)).toEqual( expectedList, ); // assert lset with a negative index for the last element in the list - expect(await client.lset(key, negativeIndex, element)).toEqual( - "OK", - ); + checkSimple( + await client.lset(key, negativeIndex, element), + ).toEqual("OK"); checkSimple(await client.lrange(key, 0, negativeIndex)).toEqual( expectedList2, ); + + // assert lset against a non-list key + const nonListKey = "nonListKey"; + expect(await client.sadd(nonListKey, ["a"]),).toEqual(1); + + try { + checkSimple(await client.lset(nonListKey, 0, "b")); + } catch (e) { + expect((e as Error).message).toMatch( + "WRONGTYPE: Operation against a key holding the wrong kind of value", + ); + } }, protocol); }, config.timeout,