Skip to content

Commit

Permalink
Add a test for generic mixins.
Browse files Browse the repository at this point in the history
  • Loading branch information
bicknellr committed Jan 5, 2023
1 parent 732c6fd commit a3de3ba
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion test/flavors/custom-element/member-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ tsTest("Member types can be retrieved", t => {
t.truthy(isAssignableToType({ kind: "NUMBER" }, toSimpleType(type, checker)));
});

tsTest("Property declaration member types are specialized", t => {
tsTest("Property declaration member types are specialized (classes)", t => {
const {
results: [result],
checker
Expand Down Expand Up @@ -70,6 +70,44 @@ tsTest("Property declaration member types are specialized", t => {
t.truthy(isAssignableToType(optional({ kind: "BOOLEAN" }), toSimpleType(booleanElementPropType, checker)));
});

tsTest("Property declaration member types are specialized (mixins)", t => {
const {
results: [result],
checker
} = analyzeTextWithCurrentTsModule([
{
fileName: "main.ts",
text: `
const SomeMixin = <T, C>(Base: C) => {
class Mixin extends Base {
prop?: T;
}
return Mixin;
}
class NumberPropElement extends SomeMixin<number>(HTMLElement) {}
class BooleanPropElement extends SomeMixin<boolean>(HTMLElement) {}
declare global {
interface HTMLElementTagNameMap {
"number-prop-element": NumberPropElement;
"boolean-prop-element": BooleanPropElement;
}
}
`
}
]);

const numberElementDecl = result.componentDefinitions.find(x => x.tagName === "number-prop-element")!.declaration!;
const numberElementPropType = getComponentProp(numberElementDecl.members, "prop")!.type!(numberElementDecl);
t.truthy(isAssignableToType(optional({ kind: "NUMBER" }), toSimpleType(numberElementPropType, checker)));

const booleanElementDecl = result.componentDefinitions.find(x => x.tagName === "boolean-prop-element")!.declaration!;
const booleanElementPropType = getComponentProp(booleanElementDecl.members, "prop")!.type!(booleanElementDecl);
t.truthy(isAssignableToType(optional({ kind: "BOOLEAN" }), toSimpleType(booleanElementPropType, checker)));
});

tsTest("Getter member types are specialized", t => {
const {
results: [result],
Expand Down

0 comments on commit a3de3ba

Please sign in to comment.