Skip to content

Commit

Permalink
Fixes #391
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasrueedlinger authored and andreasrueedlinger committed Oct 14, 2016
1 parent a878641 commit fecb8c5
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/serializers/text/binding_serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
40 changes: 40 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>(TYPES.MyStringValue).toConstantValue("foo");

let out = "";
let logger = makeLoggerMiddleware(null, (entry) => { out = textSerializer(entry); });
kernel.applyMiddleware(logger);
kernel.get<string>(TYPES.MyStringValue);

let expectedOut = "SUCCESS: 0.75 ms.\n" +
" └── Request : 0\n" +
" └── serviceIdentifier : Symbol(MyStringValue)\n" +
" └── bindings\n" +
" └── Binding<Symbol(MyStringValue)> : 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);
}
});

});

});

0 comments on commit fecb8c5

Please sign in to comment.