|
| 1 | +import type * as d from '../../../declarations'; |
| 2 | +import { generateComponentTypes } from '../generate-component-types'; |
| 3 | +import { stubComponentCompilerMeta } from './ComponentCompilerMeta.stub'; |
| 4 | +import { stubTypesImportData } from './TypesImportData.stub'; |
| 5 | + |
| 6 | +describe('generate-component-types', () => { |
| 7 | + describe('generateComponentTypes', () => { |
| 8 | + it('default', () => { |
| 9 | + // given |
| 10 | + const componentCompilerMeta = stubComponentCompilerMeta(); |
| 11 | + const typeImportData = stubTypesImportData(); |
| 12 | + |
| 13 | + // when |
| 14 | + const typesModule: d.TypesModule = generateComponentTypes(componentCompilerMeta, typeImportData, false); |
| 15 | + |
| 16 | + // then |
| 17 | + expect(typesModule).toEqual<d.TypesModule>({ |
| 18 | + component: ` interface StubCmp { |
| 19 | + }`, |
| 20 | + element: ` interface HTMLStubCmpElement extends Components.StubCmp, HTMLStencilElement { |
| 21 | + prototype: HTMLStubCmpElement; |
| 22 | + new (): HTMLStubCmpElement; |
| 23 | + } |
| 24 | + var HTMLStubCmpElement: HTMLStubCmpElement;`, |
| 25 | + htmlElementName: `HTMLStubCmpElement`, |
| 26 | + isDep: false, |
| 27 | + jsx: ` interface StubCmp { |
| 28 | + }`, |
| 29 | + tagName: 'stub-cmp', |
| 30 | + tagNameAsPascal: 'StubCmp', |
| 31 | + }); |
| 32 | + }); |
| 33 | + |
| 34 | + it('with type parameters', () => { |
| 35 | + // given |
| 36 | + const componentCompilerMeta = stubComponentCompilerMeta(); |
| 37 | + const typeImportData = stubTypesImportData(); |
| 38 | + componentCompilerMeta.componentClassTypeParameters = ['a', 'b']; |
| 39 | + |
| 40 | + // when |
| 41 | + const typesModule: d.TypesModule = generateComponentTypes(componentCompilerMeta, typeImportData, false); |
| 42 | + |
| 43 | + // then |
| 44 | + expect(typesModule).toEqual<d.TypesModule>({ |
| 45 | + component: ` interface StubCmp<a,b> { |
| 46 | + }`, |
| 47 | + element: ` interface HTMLStubCmpElement<a,b> extends Components.StubCmp<a,b>, HTMLStencilElement { |
| 48 | + prototype: HTMLStubCmpElement<a,b>; |
| 49 | + new (): HTMLStubCmpElement<a,b>; |
| 50 | + } |
| 51 | + var HTMLStubCmpElement: HTMLStubCmpElement<any,any>;`, |
| 52 | + htmlElementName: `HTMLStubCmpElement<any,any>`, |
| 53 | + isDep: false, |
| 54 | + jsx: ` interface StubCmp<a,b> { |
| 55 | + }`, |
| 56 | + tagName: 'stub-cmp', |
| 57 | + tagNameAsPascal: 'StubCmp<any,any>', |
| 58 | + }); |
| 59 | + }); |
| 60 | + }); |
| 61 | +}); |
0 commit comments