import { Component, mount, useState, xml } from "../../src";
import { makeTestFixture, nextTick, snapshotEverything } from "../helpers";
snapshotEverything();
let fixture: HTMLElement;
beforeEach(() => {
fixture = makeTestFixture();
});
describe("t-props", () => {
test("t-props only", async () => {
class Comp extends Component {
static template = xml`
`;
}
class Parent extends Component {
static components = { Comp };
static template = xml``;
state = useState({
a: "first",
});
}
const parent = await mount(Parent, fixture);
expect(fixture.textContent).toBe("first");
parent.state.a = "";
await nextTick();
expect(fixture.textContent).toBe("");
parent.state.a = "fixed";
await nextTick();
expect(fixture.textContent).toBe("fixed");
});
test("t-props and other props", async () => {
class Comp extends Component {
static template = xml`
`;
}
class Parent extends Component {
static components = { Comp };
static template = xml``;
state1 = useState({
a: "first",
b: "second",
});
a = "third";
}
const parent = await mount(Parent, fixture);
expect(fixture.textContent).toBe("thirdsecond");
delete parent.a;
parent.render();
await nextTick();
expect(fixture.textContent).toBe("second");
});
test("basic use", async () => {
expect.assertions(5);
let props = { a: 1, b: 2 };
class Child extends Component {
static template = xml`
`;
setup() {
expect(this.props).toEqual({ a: 1, b: 2 });
expect(this.props).toBe(props);
}
}
class Parent extends Component {
static template = xml`
`;
static components = { Child };
some = { obj: props };
}
await mount(Parent, fixture);
expect(fixture.innerHTML).toBe("3
");
});
test("t-props with props", async () => {
expect.assertions(3); // 2 comes from snapshots
class Child extends Component {
static template = xml``;
setup() {
expect(this.props).toEqual({ a: 1, b: 2, c: "c" });
}
}
class Parent extends Component {
static template = xml`
`;
static components = { Child };
props = { a: "a", c: "c" };
}
await mount(Parent, fixture);
});
});