import { render, CustomElement, Host, defineElement, state, prop } from "@cerxes/csx";
import { testContainer } from "../utils/test-container";
import { nextAnimationFrame } from "../utils/next-animation-frame";
describe("Inheritance tests", () => {
/**
* Assert that a we can extend a getter/setter prop
*/
test("Single inherited getter/setter-property", async () => {
@defineElement('base-component')
class BaseComponent extends CustomElement{
@prop()
set name(value){
if(this.#name!==value){
this.#name = value;
}
}
get name(){
return this.#name;
}
#name;
render(){
return (
{this.name}
)
}
}
@defineElement('extended-component')
class ExtendedComponent extends BaseComponent{
@prop()
set name(value){
super.name = `Hi my name is ${value??""}`;
}
get name(){
return super.name;
}
}
let container = testContainer(
render()
);
document.body.appendChild(container);// Components need to be added to the DOM or their connectecCallback will not be called
expect(
container.innerHTML
).toBe([
``,
`
`,
``,
`
Hi my name is Slim Shady
`,
`
`,
``,
].join(''));
document.body.removeChild(container);
});
/**
* Assert that a we can extend a basic prop with a get/set
* This test is expected to fail as long as decorators don't fully work as expected in babel
* The problem showing up here is an initalizerDefineProperty being called in the base class, that replaces
* the end descriptor of the function in the extended version
*/
test("Single inherited basic-property component", async () => {
@defineElement('base-component-2')
class BaseComponent extends CustomElement{
@prop()
name;
render(){
return (
{this.name}
)
}
}
@defineElement('extended-component-2')
class ExtendedComponent extends BaseComponent{
@prop()
set name(value){
super.name = `Hi my name is ${value??""}`;
}
get name(){
return super.name;
}
}
let container = testContainer(
render()
);
document.body.appendChild(container);// Components need to be added to the DOM or their connectecCallback will not be called
expect(
container.innerHTML
).toBe([
``,
`