Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
add spy
Browse files Browse the repository at this point in the history
  • Loading branch information
KATT committed Oct 5, 2023
1 parent 931bd99 commit 15c7b94
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/async/deserializeAsync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,16 @@ test("e2e: stringify and parse promise with a promise over a network connection"
assert(response.body);

const textDecoder = new TextDecoder();

const spy = vi.fn();
const stringIterator = mapIterable(
readableStreamToAsyncIterable(response.body),
(v) => textDecoder.decode(v),
mapIterable(readableStreamToAsyncIterable(response.body), (v) =>
textDecoder.decode(v),
),
(val) => {
spy(val.trimEnd());
return val;
},
);

const parsedRaw = await tson.parse(stringIterator);
Expand All @@ -148,6 +155,22 @@ test("e2e: stringify and parse promise with a promise over a network connection"
results.push(value);
}

// eslint-disable-next-line @typescript-eslint/no-unsafe-return
expect(spy.mock.calls.map((it) => it[0])).toMatchInlineSnapshot(`
[
"[
{\\"json\\":{\\"foo\\":\\"bar\\",\\"iterable\\":[\\"AsyncIterator\\",0,\\"__tson\\"],\\"promise\\":[\\"Promise\\",1,\\"__tson\\"]},\\"nonce\\":\\"__tson\\"}
,
[
[1,[0,42]]",
" ,[0,[0,[\\"bigint\\",\\"1\\",\\"__tson\\"]]]",
" ,[0,[0,[\\"bigint\\",\\"2\\",\\"__tson\\"]]]
,[0,[2]]
]
]",
]
`);

expect(results).toEqual([1n, 2n]);
server.close();
});

0 comments on commit 15c7b94

Please sign in to comment.