Skip to content

Commit 399e262

Browse files
committed
test: add tests to decodeAsync with custom extensionCodec
1 parent 3bbe32a commit 399e262

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

test/ExtensionCodec.test.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import assert from "assert";
22
import util from "util";
3-
import { encode, decode, ExtensionCodec, EXT_TIMESTAMP } from "../src";
3+
import { encode, decode, ExtensionCodec, EXT_TIMESTAMP, decodeAsync } from "../src";
44

55
/* eslint-disable @typescript-eslint/no-non-null-assertion */
66

@@ -74,11 +74,21 @@ describe("ExtensionCodec", () => {
7474
},
7575
});
7676

77-
it("encodes and decodes custom data types", () => {
77+
it("encodes and decodes custom data types (synchronously)", () => {
7878
const set = new Set([1, 2, 3]);
7979
const map = new Map([["foo", "bar"], ["bar", "baz"]]);
8080
const encoded = encode([set, map], { extensionCodec });
8181
assert.deepStrictEqual(decode(encoded, { extensionCodec }), [set, map]);
8282
});
83+
84+
it("encodes and decodes custom data types (asynchronously)", async () => {
85+
const set = new Set([1, 2, 3]);
86+
const map = new Map([["foo", "bar"], ["bar", "baz"]]);
87+
const encoded = encode([set, map], { extensionCodec });
88+
const createStream = async function*() {
89+
yield encoded;
90+
};
91+
assert.deepStrictEqual(await decodeAsync(createStream(), { extensionCodec }), [set, map]);
92+
});
8393
});
8494
});

0 commit comments

Comments
 (0)