Skip to content

Commit

Permalink
test(integration-karma): template expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
divmain committed Mar 11, 2023
1 parent f02b1b8 commit 95b0a46
Show file tree
Hide file tree
Showing 13 changed files with 78 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/@lwc/integration-karma/scripts/karma-plugins/lwc.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ function createPreprocessor(config, emitter, logger) {
.join('\n');
const outro = ancestorDirectories.map(() => `});`).join('\n');

// TODO [#3370]: remove experimental template expression flag
const experimentalComplexExpressions = suiteDir.includes('template-expressions');

const plugins = [
lwcRollupPlugin({
sourcemap: true,
Expand All @@ -50,6 +53,7 @@ function createPreprocessor(config, emitter, logger) {
},
enableLwcSpread: true,
enableDynamicComponents: true,
experimentalComplexExpressions,
disableSyntheticShadowSupport: DISABLE_SYNTHETIC_SHADOW_SUPPORT_IN_COMPILER,
}),
];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { createElement } from 'lwc';

import UndefinedMemberExpressionObjParent from 'x/undefinedMemberExpressionObjParent';
import ThrowDuringCallParent from 'x/throwDuringCallParent';

it(`should handle member expression with undefined object`, () => {
const parent = createElement('x-parent', { is: UndefinedMemberExpressionObjParent });
document.body.appendChild(parent);
expect(parent.caughtError).toContain('undefined');
});

it(`should handle errors thrown during call expression`, () => {
const parent = createElement('x-parent', { is: ThrowDuringCallParent });
document.body.appendChild(parent);
expect(parent.caughtError).toContain("I'm the Gingerbread man!");
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<div foo={runRunAsFastAsYouCan()}></div>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { LightningElement } from 'lwc';

export default class Test extends LightningElement {
runRunAsFastAsYouCan() {
throw new Error("You can't catch me, I'm the Gingerbread man!");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<x-throw-during-call-child></x-throw-during-call-child>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { LightningElement, api } from 'lwc';

export default class Parent extends LightningElement {
@api caughtError = null;
errorCallback(err) {
this.caughtError = err.message;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<div foo={nonexistent.thing}></div>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { LightningElement } from 'lwc';

export default class Test extends LightningElement {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<x-undefined-member-expression-obj-child></x-undefined-member-expression-obj-child>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { LightningElement, api } from 'lwc';

export default class Parent extends LightningElement {
@api caughtError = null;
errorCallback(err) {
this.caughtError = err.message;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { createElement } from 'lwc';

import Test from 'x/test';

it(`should support call expressions`, () => {
const elm = createElement('x-test', { is: Test });
document.body.appendChild(elm);

expect(elm.shadowRoot.querySelector('div').getAttribute('foo')).toBe('bar');
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<div foo={bar()}></div>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { LightningElement } from 'lwc';

export default class Test extends LightningElement {
bar() {
return 'bar';
}
}

0 comments on commit 95b0a46

Please sign in to comment.