import { Component, Event, EventEmitter, h, MixedInCtor, Mixin, Prop, State } from '@stencil/core'; import { newSpecPage } from '@stencil/core/testing'; describe('mixin', () => { it('can call a constructor with args', async () => { const MyMixin = (Base: B) => { class Test extends Base { constructor(...args: any[]) { super(...args); } @State() test = 'testing!!'; } return Test; }; @Component({ tag: 'arg-test' }) class CmpA extends Mixin(MyMixin) { @Prop() value: string; render() { return ( {this.value.trim()} {this.test} ); } } const { root } = await newSpecPage({ components: [CmpA], html: ``, }); expect(root).not.toBeFalsy(); }); it('can initialize with a @Prop with an initial value', async () => { const MyMixin = (Base: B) => { class Test extends Base { @Prop({ mutable: true }) testProp = 'ABC'; } return Test; }; @Component({ tag: 'mixin-test', }) class MixinTest extends Mixin(MyMixin) { render() { return {this.testProp}; } } const { root } = await newSpecPage({ components: [MyMixin, MixinTest], html: ``, }); expect(root).toEqualHtml(` ABC `); }); it('can initialize with an @Event', async () => { const MyMixin = (Base: B) => { class Test extends Base { public emitTest() { (this as any).test.emit(); } } return Test; }; @Component({ tag: 'mixin-test', }) class MixinTest extends Mixin(MyMixin) { @Event() test: EventEmitter; componentDidLoad() { this.emitTest(); } } const { root } = await newSpecPage({ components: [MixinTest], html: ``, }); expect(root).toEqualHtml(` `); }); });