Skip to content

Commit

Permalink
add some regression tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tanner-reits committed Jul 6, 2023
1 parent 9f3e4b5 commit eadaac1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/compiler/transformers/test/lazy-component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,33 @@ describe('lazy-component', () => {
expect(t.outputText).toContain(`import { registerInstance as __stencil_registerInstance } from "@stencil/core"`);
expect(t.outputText).toContain(`__stencil_registerInstance(this, hostRef)`);
});

it('adds a getter for an @Element() reference', () => {
const compilerCtx = mockCompilerCtx();
const transformOpts: d.TransformOptions = {
coreImportPath: '@stencil/core',
componentExport: 'lazy',
componentMetadata: null,
currentDirectory: '/',
proxy: null,
style: 'static',
styleImportData: null,
};

const code = `
@Component({
tag: 'cmp-a'
})
export class CmpA {
@Element() el: HtmlElement;
}
`;

const transformer = lazyComponentTransform(compilerCtx, transformOpts);

const t = transpileModule(code, null, compilerCtx, [], [transformer]);

expect(t.outputText).toContain(`get el() { return __stencil_getElement(this); } };`);
expect(t.outputText).not.toContain(`el;`);
});
});
18 changes: 18 additions & 0 deletions src/compiler/transformers/test/native-constructor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,23 @@ describe('nativeComponentTransform', () => {
);
expect(transpiledModule.outputText).toContain(`this.__attachShadow()`);
});

it('adds a getter for an @Element() reference', () => {
const code = `
@Component({
tag: 'cmp-a'
})
export class CmpA {
@Element() el: HtmlElement;
}
`;

const transformer = nativeComponentTransform(compilerCtx, transformOpts);

const transpiledModule = transpileModule(code, null, compilerCtx, [], [transformer]);

expect(transpiledModule.outputText).toContain(`get el() { return this; }`);
expect(transpiledModule.outputText).not.toContain(`el;`);
});
});
});

0 comments on commit eadaac1

Please sign in to comment.