diff --git a/src/json-pack/resp/RespEncoder.ts b/src/json-pack/resp/RespEncoder.ts index 2fab26868f..081be4cb1e 100644 --- a/src/json-pack/resp/RespEncoder.ts +++ b/src/json-pack/resp/RespEncoder.ts @@ -32,7 +32,8 @@ export class RespEncoder); @@ -115,11 +116,18 @@ export class RespEncoder { }); }); +describe('binary', () => { + test('empty blob', () => { + const encoder = new RespEncoder(); + const encoded = encoder.encode(new Uint8Array(0)); + expect(toStr(encoded)).toBe('$0\r\n\r\n'); + expect(parse(encoded)).toBe(''); + }); + + test('small blob', () => { + const encoder = new RespEncoder(); + const encoded = encoder.encode(new Uint8Array([65, 66])); + expect(toStr(encoded)).toBe('$2\r\nAB\r\n'); + expect(parse(encoded)).toBe('AB'); + }); +}); + describe('.writeAsciiString()', () => { test('can write "OK"', () => { const encoder = new RespEncoder();