Skip to content

Commit ac667e0

Browse files
committed
refactor: improve ts for toString
Signed-off-by: Grant Timmerman <[email protected]>
1 parent 7da6533 commit ac667e0

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/event/cloudevent.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,9 @@ See: https://github.com/cloudevents/spec/blob/v1.0/spec.md#type-system`);
198198

199199
/**
200200
* The native `console.log` value of the CloudEvent.
201-
* @return The string representation of the CloudEvent.
201+
* @return {string} The string representation of the CloudEvent.
202202
*/
203-
[Symbol.for("nodejs.util.inspect.custom")]() {
203+
[Symbol.for("nodejs.util.inspect.custom")](): string {
204204
return this.toString();
205205
}
206206
}

test/integration/cloud_event_test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ describe("A CloudEvent", () => {
5757

5858
it("serializes as JSON with raw log", () => {
5959
const ce = new CloudEvent({ ...fixture, data: { lunch: "tacos" } });
60-
expect(ce.toString()).to.deep.equal(JSON.stringify(ce));
60+
const inspectSymbol = (Symbol.for("nodejs.util.inspect.custom") as unknown) as string;
61+
const ceToString = (ce[inspectSymbol] as CallableFunction).bind(ce);
62+
expect(ce.toString()).to.deep.equal(ceToString());
6163
});
6264

6365
it("Throw a validation error for invalid extension names", () => {

0 commit comments

Comments
 (0)