[IMP] qweb: add warning if t-key is missing in some cases

closes #71
This commit is contained in:
Géry Debongnie
2019-05-03 09:49:25 +02:00
parent d3197e9865
commit 4e982f5460
4 changed files with 71 additions and 6 deletions
+21 -2
View File
@@ -726,10 +726,29 @@ describe("foreach", () => {
test("throws error if invalid loop expression", () => {
qweb.addTemplate(
"test",
`<div><t t-foreach="abc" t-as="item"><span/></t></div>`
`<div><t t-foreach="abc" t-as="item"><span t-key="item_index"/></t></div>`
);
expect(() => qweb.render("test")).toThrow("Invalid loop expression");
});
test("warn if no key in some case", () => {
const consoleWarn = console.warn;
console.warn = jest.fn();
qweb.addTemplate(
"test",
`
<div>
<t t-foreach="[1, 2]" t-as="item">
<span><t t-esc="item"/></span>
</t>
</div>`
);
renderToString(qweb, "test");
expect(console.warn).toHaveBeenCalledTimes(1);
console.warn = consoleWarn;
});
});
describe("misc", () => {
@@ -966,7 +985,7 @@ describe("t-ref", () => {
qweb.addTemplate("test", `
<div>
<t t-foreach="items" t-as="item">
<div t-ref="item"><t t-esc="item"/></div>
<div t-ref="item" t-key="item"><t t-esc="item"/></div>
</t>
</div>`);
let refs: any = {};