Skip to content

Commit 5a2358b

Browse files
committed
test(integration-karma): add tests for objects with computed key
1 parent 2e5bf3d commit 5a2358b

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

packages/@lwc/integration-karma/test/lwc-on/index.spec.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import Lifecycle from 'x/lifecycle';
88
import Rerender from 'x/rerender';
99
import RerenderLoop from 'x/rerenderLoop';
1010
import PublicProp from 'x/publicProp';
11-
12-
// import { catchUnhandledRejectionsAndErrors, spyConsole } from 'test-utils';
11+
import ComputedKey from 'x/computedKey';
1312

1413
describe('lwc:on', () => {
1514
it('adds multiple event listeners', () => {
@@ -346,4 +345,15 @@ describe('lwc:on', () => {
346345
button.click();
347346
expect(testFn).toHaveBeenCalled();
348347
});
348+
349+
it('works properly with objects whose keys are computed', () => {
350+
const element = createElement('x-computed-key', { is: ComputedKey });
351+
const testFn = jasmine.createSpy('test function');
352+
element.testFn = testFn;
353+
document.body.appendChild(element);
354+
const button = element.shadowRoot.querySelector('button');
355+
356+
button.click();
357+
expect(testFn).toHaveBeenCalled();
358+
});
349359
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<template>
2+
<button lwc:on={eventHandlers}>Click Me</button>
3+
</template>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { LightningElement, api } from 'lwc';
2+
3+
let testFn;
4+
const mouseover = 'click';
5+
6+
export default class ComputedKey extends LightningElement {
7+
@api
8+
get testFn() {
9+
return testFn;
10+
}
11+
set testFn(val) {
12+
testFn = val;
13+
}
14+
15+
eventHandlers = {
16+
[mouseover]: function () {
17+
testFn();
18+
},
19+
};
20+
}

0 commit comments

Comments
 (0)