mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
27629cedfa
the low level method htmlelement.classList.add does not accept multiple
classes in one string, which is why, in owl, the expression
`<div t-att-class="{'a b c': value}" />`
did not work as one might expect. It is however very convenient in real
life templates, so this commit improve owl by adding support for this
feature.
closes #813
28 lines
950 B
TypeScript
28 lines
950 B
TypeScript
import { QWeb } from "../../src/qweb/index";
|
|
import { renderToString } from "../helpers";
|
|
|
|
//------------------------------------------------------------------------------
|
|
// Setup and helpers
|
|
//------------------------------------------------------------------------------
|
|
|
|
function render(template, context = {}) {
|
|
const qweb = new QWeb();
|
|
qweb.addTemplate("test", template);
|
|
return renderToString(qweb, "test", context);
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
|
// Tests
|
|
//------------------------------------------------------------------------------
|
|
|
|
describe("qweb t-att", () => {
|
|
test("t-att-class with multiple classes", () => {
|
|
expect(render(`<div t-att-class="{'a b c': value}" />`, { value: true })).toBe(
|
|
'<div class="a b c"></div>'
|
|
);
|
|
expect(render(`<div t-att-class="{['a b c']: value}" />`, { value: true })).toBe(
|
|
'<div class="a b c"></div>'
|
|
);
|
|
});
|
|
});
|