File tree Expand file tree Collapse file tree 3 files changed +35
-2
lines changed
packages/@lwc/integration-karma/test/lwc-on Expand file tree Collapse file tree 3 files changed +35
-2
lines changed Original file line number Diff line number Diff line change @@ -8,8 +8,7 @@ import Lifecycle from 'x/lifecycle';
8
8
import Rerender from 'x/rerender' ;
9
9
import RerenderLoop from 'x/rerenderLoop' ;
10
10
import PublicProp from 'x/publicProp' ;
11
-
12
- // import { catchUnhandledRejectionsAndErrors, spyConsole } from 'test-utils';
11
+ import ComputedKey from 'x/computedKey' ;
13
12
14
13
describe ( 'lwc:on' , ( ) => {
15
14
it ( 'adds multiple event listeners' , ( ) => {
@@ -346,4 +345,15 @@ describe('lwc:on', () => {
346
345
button . click ( ) ;
347
346
expect ( testFn ) . toHaveBeenCalled ( ) ;
348
347
} ) ;
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
+ } ) ;
349
359
} ) ;
Original file line number Diff line number Diff line change
1
+ < template >
2
+ < button lwc:on ={eventHandlers} > Click Me</ button >
3
+ </ template >
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments