Skip to content

Commit e545fc0

Browse files
committed
conat: more basic tests
1 parent a1bef8a commit e545fc0

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/packages/nats/core/client.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,9 @@ export class Client {
512512
// **right now** or received these messages.
513513
count: number;
514514
}> => {
515+
if (mesg === undefined) {
516+
throw Error("mesg must not be undefined");
517+
}
515518
const { bytes, getCount, promise } = this._publish(subject, mesg, {
516519
...opts,
517520
confirm: true,

src/packages/server/nats/test/core/basic.test.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,18 @@ describe("basic test of publish and subscribe", () => {
4242
expect(done).toBe(false);
4343
});
4444

45+
it("publishing undefined is not allowed", async () => {
46+
await expect(
47+
async () => await cn.publish(subject, undefined),
48+
).rejects.toThrowError("must not be undefined");
49+
50+
expect(() => cn.publishSync(subject, undefined)).toThrow(
51+
"must not be undefined",
52+
);
53+
});
54+
4555
it("publishes using a second client", async () => {
46-
const data = "client2";
56+
const data = null;
4757
cn2 = connect();
4858
expect(cn === cn2).toEqual(false);
4959
await cn2.publish(subject, data);
@@ -202,7 +212,7 @@ describe("basic tests of request/respond", () => {
202212
it("create a requestMany server that iterates over what you send it", async () => {
203213
// This example illustrates how to define a requestMany server
204214
// and includes error handling. Note the technique of using
205-
// the *headers* for control signalling (e.g., when we're done, or if
215+
// the *headers* for control signalling (e.g., when we're done, or if
206216
// there is an error) and using the message payload for the actual data.
207217
// In Conat headers are very well supported, encouraged, and easy to use
208218
// (and arbitrary JSON), unlike NATS.js.

0 commit comments

Comments
 (0)