Skip to content

Commit

Permalink
Refactor test code to remove undeterministic Promise
Browse files Browse the repository at this point in the history
  • Loading branch information
gwbaik9717 committed Aug 30, 2024
1 parent e88e3c1 commit 43ae22c
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/sdk/test/integration/client_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ describe.sequential('Client', function () {
it('Should throw error when broadcasting unserializeable payload', async ({
task,
}) => {
const spy = vi.fn();
const eventCollector = new EventCollector<string>();
const cli = new yorkie.Client(testRPCAddr);
await cli.activate();

Expand All @@ -894,13 +894,15 @@ describe.sequential('Client', function () {
// broadcast unserializable payload
const payload = () => {};
const broadcastTopic = 'test';
const broadcastErrMessage = 'payload is not serializable';

doc.broadcast(broadcastTopic, payload, spy);
const errorHandler = (error: Error) => {
eventCollector.add(error.message);
};

// Assuming that every subscriber can receive the broadcast event within 1000ms.
await new Promise((res) => setTimeout(res, 1000));
doc.broadcast(broadcastTopic, payload, errorHandler);

expect(spy).toBeCalledTimes(1);
await eventCollector.waitAndVerifyNthEvent(1, broadcastErrMessage);

await cli.deactivate();
});
Expand Down

0 comments on commit 43ae22c

Please sign in to comment.