@@ -9,7 +9,7 @@ describe('useMutationObserver', () => {
99 const spy = jest . fn ( ( ) => teardown )
1010
1111 function Wrapper ( props ) {
12- const [ el , attachRef ] = useCallbackRef ( )
12+ const [ el , attachRef ] = useCallbackRef < HTMLElement > ( )
1313
1414 useMutationObserver ( el , { attributes : true } , spy )
1515
@@ -38,4 +38,53 @@ describe('useMutationObserver', () => {
3838 // coverage on the teardown
3939 wrapper . unmount ( )
4040 } )
41+
42+ let disconnentSpy : jest . SpyInstance < void , [ ] >
43+ afterEach ( ( ) => {
44+ disconnentSpy ?. mockRestore ( )
45+ } )
46+
47+ it . only ( 'should update config' , async ( ) => {
48+ const teardown = jest . fn ( )
49+ const spy = jest . fn ( ( ) => teardown )
50+
51+ disconnentSpy = jest . spyOn ( MutationObserver . prototype , 'disconnect' )
52+
53+ function Wrapper ( { attributeFilter, ...props } ) {
54+ const [ el , attachRef ] = useCallbackRef < HTMLElement > ( )
55+
56+ useMutationObserver ( el , { attributes : true , attributeFilter } , spy )
57+
58+ return < div ref = { attachRef } { ...props } />
59+ }
60+
61+ const wrapper = mount ( < Wrapper attributeFilter = { [ 'data-name' ] } /> )
62+
63+ wrapper . setProps ( { role : 'presentation' } )
64+
65+ await Promise . resolve ( )
66+
67+ // console.log(spy.mock.calls[0][0][0].attributes)
68+ expect ( spy ) . toHaveBeenCalledTimes ( 0 )
69+
70+ wrapper . setProps ( { attributeFilter : undefined , role : 'button' } )
71+
72+ await Promise . resolve ( )
73+
74+ expect ( spy ) . toHaveBeenCalledTimes ( 1 )
75+
76+ expect ( spy ) . toHaveBeenCalledWith (
77+ [
78+ expect . objectContaining ( {
79+ type : 'attributes' ,
80+ attributeName : 'role' ,
81+ } ) ,
82+ ] ,
83+ expect . anything ( ) ,
84+ )
85+
86+ wrapper . unmount ( )
87+
88+ expect ( disconnentSpy ) . toBeCalledTimes ( 2 )
89+ } )
4190} )
0 commit comments