From fecb8c548978b30841fa972b280570697127fd24 Mon Sep 17 00:00:00 2001 From: andreasrueedlinger Date: Fri, 14 Oct 2016 21:19:42 +0200 Subject: [PATCH] Fixes #391 --- src/serializers/text/binding_serializer.ts | 2 +- test/index.test.ts | 40 ++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/serializers/text/binding_serializer.ts b/src/serializers/text/binding_serializer.ts index 91b6716..864d3f7 100644 --- a/src/serializers/text/binding_serializer.ts +++ b/src/serializers/text/binding_serializer.ts @@ -20,7 +20,7 @@ function serializeBinding( let _b: any = binding; props.forEach((prop) => { - if (_b[prop] !== undefined) { + if (_b[prop] !== undefined && _b[prop] !== null) { let val: any = _b[prop]; switch (prop) { case "type": diff --git a/test/index.test.ts b/test/index.test.ts index c16ef32..5c55e73 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -512,4 +512,44 @@ describe("makeLoggerMiddleware", () => { }); + it("Should be able to serialize constant values like strings", () => { + + const TYPES = { + MyStringValue: Symbol("MyStringValue") + }; + + const kernel = new Kernel(); + kernel.bind(TYPES.MyStringValue).toConstantValue("foo"); + + let out = ""; + let logger = makeLoggerMiddleware(null, (entry) => { out = textSerializer(entry); }); + kernel.applyMiddleware(logger); + kernel.get(TYPES.MyStringValue); + + let expectedOut = "SUCCESS: 0.75 ms.\n" + + " └── Request : 0\n" + + " └── serviceIdentifier : Symbol(MyStringValue)\n" + + " └── bindings\n" + + " └── Binding : 0\n" + + " └── type : ConstantValue\n" + + " └── scope : Transient\n"; + + let lines = out.split("└── ") + .map((line) => { + return line.split("\u001b[33m").join("") + .split("\u001b[39m").join(""); + }); + + let expectedLines = expectedOut.split("└── "); + + lines.forEach((line: string, index: number) => { + if (index > 0) { + expect(line.trim()).eql(expectedLines[index].trim()); + } else { + expect(line.indexOf("SUCCESS")).not.to.eql(-1); + } + }); + + }); + });