Skip to content
Permalink
Browse files

fix(t-attribute): undefined and null bound values (#314)

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 committed Feb 19, 2020
1 parent 0276f9c commit 2a61ee75becd9e7903086c38d6341a405e8c01f0
Showing with 70 additions and 24 deletions.
  1. +35 −23 package-lock.json
  2. +1 −1 src/i18n.ts
  3. +34 −0 test/unit/t-attribute.spec.ts

Some generated files are not rendered by default. Learn more.

@@ -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(";");
@@ -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.
You can’t perform that action at this time.