Skip to content

Commit

Permalink
Restoring offsetHeight mock
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewhayward committed Jan 24, 2024
1 parent b2fac36 commit e7f4d59
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions packages/components/src/popover/test/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,24 @@ type PlacementToInitialTranslationTuple = [
CSSProperties[ 'translate' ],
];

jest.spyOn( HTMLElement.prototype, 'offsetHeight', 'get' ).mockImplementation(
function getOffsetHeight( this: HTMLElement ) {
if ( this.tagName === 'BODY' ) {
return window.outerHeight;
}
return 50;
}
);
let offsetHeightSpy: jest.SpiedGetter<
typeof HTMLElement.prototype.offsetHeight
>;

beforeAll( () => {
offsetHeightSpy = jest
.spyOn( HTMLElement.prototype, 'offsetHeight', 'get' )
.mockImplementation( function getOffsetHeight( this: HTMLElement ) {
if ( this.tagName === 'BODY' ) {
return window.outerHeight;
}
return 50;
} );
} );

afterAll( () => {
offsetHeightSpy?.mockRestore();
} );

// There's no matching `placement` for 'middle center' positions,
// fallback to 'bottom' (same as `floating-ui`'s default.)
Expand Down

0 comments on commit e7f4d59

Please sign in to comment.