Skip to content

Commit

Permalink
Merge pull request #32 from andreasrueedlinger/master
Browse files Browse the repository at this point in the history
Fixes #391
  • Loading branch information
remojansen authored Oct 14, 2016
2 parents a878641 + 63877da commit f7f3fd7
Show file tree
Hide file tree
Showing 2 changed files with 42 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 @@ -30,7 +30,7 @@ function serializeBinding(
val = scopeFormatter(_b[prop]);
break;
case "implementationType":
val = _b[prop].name;
val = _b[prop] && _b[prop].name;
break;
case "serviceIdentifier":
val = serviceIdentifierFormatter(_b[prop]);
Expand Down
41 changes: 41 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,4 +512,45 @@ 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" +
" └── implementationType : null\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 f7f3fd7

Please sign in to comment.