-
Notifications
You must be signed in to change notification settings - Fork 255
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3959 from ProjectMirador/no-sizme
Remove react-sizeme to silence findDOMNode deprecation warnings
- Loading branch information
Showing
7 changed files
with
219 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import PropTypes from 'prop-types'; | ||
import { withSize } from '../../../src/extend/withSize'; | ||
|
||
/** Mock ResizeObserver */ | ||
class ResizeObserver { | ||
/** */ | ||
constructor(callback) { | ||
this.callback = callback; | ||
} | ||
|
||
/** */ | ||
observe(element) { | ||
// Fake a resize event | ||
setTimeout(() => { | ||
this.callback([{ contentRect: { height: 300, width: 400 } }]); | ||
}, 0); | ||
} | ||
|
||
/** */ | ||
disconnect() { jest.fn(); } // eslint-disable-line | ||
} | ||
|
||
// Replace the global ResizeObserver with the mock | ||
global.ResizeObserver = ResizeObserver; | ||
|
||
/** */ | ||
const TestComponent = ({ size }) => ( | ||
<div> | ||
{size.width} | ||
{size.height} | ||
</div> | ||
); | ||
|
||
TestComponent.propTypes = { | ||
size: PropTypes.shape({ | ||
height: PropTypes.number, | ||
width: PropTypes.number, | ||
}).isRequired, | ||
}; | ||
|
||
const WrappedTestComponent = withSize()(TestComponent); | ||
|
||
test('it should render with size', async () => { | ||
render(<WrappedTestComponent />); | ||
|
||
// Assert that the updated size is reflected | ||
expect(await screen.findByText(/400/)).toBeInTheDocument(); | ||
expect(await screen.findByText(/300/)).toBeInTheDocument(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.