Skip to content

Commit

Permalink
fix(t-attribute): undefined and null bound values (#314)
Browse files Browse the repository at this point in the history
if the provided value is bound to a null or undefined property
the resulting value for translation should be an empty string

fixes issue #313
  • Loading branch information
zewa666 authored Feb 19, 2020
1 parent 0276f9c commit 2a61ee7
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 24 deletions.
58 changes: 35 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export class I18N {

public updateValue(node: Element & { au: any }, value: string, params: any) {
if (value === null || value === undefined) {
return;
value = "";
}

const keys = value.toString().split(";");
Expand Down
34 changes: 34 additions & 0 deletions test/unit/t-attribute.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,38 @@ describe("t-attribute", () => {

component.dispose();
});

it("should convert bound integers to strings", async () => {
const expectedValue = "";
const component = StageComponent
.withResources("mocks/rt-vm")
.inView(`<p t.bind="undef" id="undefined">
Undefined value
</p>
<p t.bind="nullul" id="null">
Null value
</p>
<p t.bind="zero" id="zero">
Zero value
</p>`)
.boundTo({
undef: undefined,
nullul: null,
zero: 0
});

bootstrapTestEnvironment(component, {
resources: {
en: { translation: { 1: expectedValue } }
}
});

await component.create(bootstrap);

expect(document.getElementById("undefined")!.innerHTML).toBe("");
expect(document.getElementById("null")!.innerHTML).toBe("");
expect(document.getElementById("zero")!.innerHTML).toBe("0");

component.dispose();
});
});

0 comments on commit 2a61ee7

Please sign in to comment.