Commit 79fdb3e 1 parent 583f759 commit 79fdb3e Copy full SHA for 79fdb3e
File tree 3 files changed +15
-0
lines changed
3 files changed +15
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { withResizeObserverMock } from 'testing-utils/mocks/withResizeObserverMock' ;
2
+
1
3
import {
2
4
getPositionStyle ,
3
5
getTargetBoundaries ,
4
6
getVariantBoundaries ,
5
7
} from './usePosition' ;
6
8
// TODO: add tests targeting the hook itself
7
9
10
+ withResizeObserverMock ( ) ;
11
+
8
12
const container = {
9
13
bottom : 1000 ,
10
14
height : 1000 ,
Original file line number Diff line number Diff line change @@ -140,10 +140,18 @@ const useBoundingClientRect = (
140
140
const parents = getScrollParents ( element . current ) ;
141
141
const passive = { passive : true } ;
142
142
143
+ const observer = new ResizeObserver ( ( ) => {
144
+ if ( ! element . current ) {
145
+ return ;
146
+ }
147
+ callback ( ) ;
148
+ } ) ;
149
+ observer . observe ( element . current ) ;
143
150
window . addEventListener ( 'resize' , callback ) ;
144
151
parents . forEach ( ( el ) => el . addEventListener ( 'scroll' , callback , passive ) ) ;
145
152
146
153
return ( ) => {
154
+ observer . disconnect ( ) ;
147
155
window . removeEventListener ( 'resize' , callback ) ;
148
156
parents . forEach ( ( el ) => el . removeEventListener ( 'scroll' , callback ) ) ;
149
157
} ;
Original file line number Diff line number Diff line change @@ -2,9 +2,12 @@ import { composeStories } from '@storybook/testing-react';
2
2
import { render , screen } from '@testing-library/react' ;
3
3
import userEvent from '@testing-library/user-event' ;
4
4
import React from 'react' ;
5
+ import { withResizeObserverMock } from 'testing-utils/mocks/withResizeObserverMock' ;
5
6
6
7
import * as stories from './Menu.stories' ;
7
8
9
+ withResizeObserverMock ( ) ;
10
+
8
11
const { Simple } = composeStories ( stories ) ;
9
12
10
13
describe ( '[Menu Component]' , ( ) => {
You can’t perform that action at this time.
0 commit comments