File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed
packages/fiori3/src/internal Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change
1
+ import { withWebComponent } from './withWebComponent' ;
2
+ import UI5Button from '@ui5/webcomponents/dist/Button' ;
3
+ import { mountThemedComponent } from '@shared/tests/utils' ;
4
+ import { expect } from 'chai' ;
5
+ import React , { FC , cloneElement } from 'react' ;
6
+ import { spy } from 'sinon' ;
7
+
8
+ describe ( 'withWebComponent' , ( ) => {
9
+ it ( 'Unmount Event Handlers correctly after prop update' , ( ) => {
10
+ let Button : FC < any > = withWebComponent ( UI5Button ) ;
11
+ const callback = spy ( ) ;
12
+ const wrapper = mountThemedComponent ( < Button onPress = { ( ...args ) => callback ( ...args ) } /> ) ;
13
+ const component = wrapper
14
+ . find ( 'ui5-button' )
15
+ . first ( )
16
+ . instance ( ) ;
17
+ // @ts -ignore
18
+ component . onclick ( { } ) ;
19
+ expect ( callback . callCount ) . to . equal ( 1 , 'onPress handler has not been called' ) ;
20
+ wrapper . setProps ( {
21
+ children : cloneElement ( wrapper . prop ( 'children' ) , { onPress : ( ...args ) => callback ( ...args ) } )
22
+ } ) ;
23
+ wrapper . update ( ) ;
24
+ // @ts -ignore
25
+ component . onclick ( { } ) ;
26
+ expect ( callback . callCount ) . to . equal ( 2 , 'onPress handler has not been called after update' ) ;
27
+ } ) ;
28
+ } ) ;
Original file line number Diff line number Diff line change @@ -96,7 +96,7 @@ export function withWebComponent<T>(WebComponent): FC<T> {
96
96
const eventHandler = this . props [ eventIdentifier ] || this . props [ alternativeKey ] ;
97
97
if ( typeof eventHandler === 'function' && this . eventRegistry [ alternativeKey ] !== eventHandler ) {
98
98
if ( this . eventRegistry [ alternativeKey ] ) {
99
- this . wcRef . removeEventListener ( eventIdentifier , this . eventRegistry [ alternativeKey ] ) ;
99
+ this . wcRef . removeEventListener ( eventIdentifier , this . eventRegistryWrapped [ alternativeKey ] ) ;
100
100
}
101
101
this . eventRegistryWrapped [ alternativeKey ] = this . createEventWrapperFor ( eventIdentifier , eventHandler ) ;
102
102
this . wcRef . addEventListener ( eventIdentifier , this . eventRegistryWrapped [ alternativeKey ] ) ;
You can’t perform that action at this time.
0 commit comments