Skip to content

Commit

Permalink
add tests for multiple-return constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
alicewriteswrongs committed Jan 22, 2024
1 parent 2a7a75e commit e73e6bf
Showing 1 changed file with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,64 @@ describe('automatic key insertion', () => {
);
});

it('should not transform JSX inside of a ternary', async () => {
jest.spyOn(keyInsertionUtils, 'deriveJSXKey').mockReturnValue('shouldnt-see-key');
const t = transpile(`
@Component({tag: 'cmp-a'})
export class CmpA {
yes = false;
render() {
return this.yes ? <span>yes</span> : <span>no</span>
}
}`);
expect(await formatCode(t.outputText)).toBe(
`export class CmpA {
constructor() {
this.yes = false;
}
render() {
return this.yes ? h('span', null, 'yes') : h('span', null, 'no');
}
static get is() {
return 'cmp-a';
}
}
`,
);
});

it('should not transform JSX in methods with multiple returns', async () => {
jest.spyOn(keyInsertionUtils, 'deriveJSXKey').mockReturnValue('shouldnt-see-key');
const t = transpile(`
@Component({tag: 'cmp-a'})
export class CmpA {
booleo = false;
render() {
if (this.booleo) {
return <div>early!</div>;
}
return <div>late!</div>;
}
}`);
expect(await formatCode(t.outputText)).toBe(
`export class CmpA {
constructor() {
this.booleo = false;
}
render() {
if (this.booleo) {
return h('div', null, 'early!');
}
return h('div', null, 'late!');
}
static get is() {
return 'cmp-a';
}
}
`,
);
});

it('should not edit a non-stencil class', async () => {
jest.spyOn(keyInsertionUtils, 'deriveJSXKey').mockReturnValue("shouldn't see this!");
const t = transpile(`
Expand Down

0 comments on commit e73e6bf

Please sign in to comment.