[IMP] qweb: make t-key directive dynamic

instead of having t-key and t-att-key.

closes #36
This commit is contained in:
Géry Debongnie
2019-04-16 14:35:27 +02:00
parent 7092f5e142
commit 0ca4cc1596
5 changed files with 84 additions and 10 deletions
+26
View File
@@ -1056,3 +1056,29 @@ describe("whitespace handling", () => {
expect(result3).toBe(pretagwithonlywhitespace);
});
});
describe("t-key", () => {
test("can use t-key directive on a node", () => {
qweb.addTemplate(
"test",
`<div t-key="beer.id"><t t-esc="beer.name"/></div>`
);
expect(
renderToString(qweb, "test", { beer: { id: 12, name: "Chimay Rouge" } })
).toBe("<div>Chimay Rouge</div>");
});
test("t-key directive in a list", () => {
qweb.addTemplate(
"test",
`<ul>
<li t-foreach="beers" t-as="beer" t-key="beer.id"><t t-esc="beer.name"/></li>
</ul>`
);
expect(
renderToString(qweb, "test", {
beers: [{ id: 12, name: "Chimay Rouge" }]
})
).toMatchSnapshot();
});
});