mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Fixed resize observer error in tests
- resize observer used in auth frame is not available in Jest, so we mock it instead - ignores missing methods on resize observer for tests
This commit is contained in:
parent
9afb36fa53
commit
beb8807966
2 changed files with 8 additions and 2 deletions
|
@ -13,7 +13,7 @@ export default class IFrame extends Component {
|
|||
componentWillUnmout() {
|
||||
this.node.removeEventListener('load', this.handleLoad);
|
||||
}
|
||||
|
||||
|
||||
setupFrameBaseStyle() {
|
||||
if (this.node.contentDocument) {
|
||||
this.iframeHtml = this.node.contentDocument.documentElement;
|
||||
|
@ -22,7 +22,7 @@ export default class IFrame extends Component {
|
|||
this.forceUpdate();
|
||||
|
||||
if (this.props.onResize) {
|
||||
(new ResizeObserver(_ => this.props.onResize(this.iframeRoot))).observe(this.iframeRoot);
|
||||
(new ResizeObserver(_ => this.props.onResize(this.iframeRoot)))?.observe?.(this.iframeRoot);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,3 +3,9 @@
|
|||
// expect(element).toHaveTextContent(/react/i)
|
||||
// learn more: https://github.com/testing-library/jest-dom
|
||||
import '@testing-library/jest-dom';
|
||||
|
||||
global.ResizeObserver = jest.fn().mockImplementation(() => ({
|
||||
observe: jest.fn(),
|
||||
unobserve: jest.fn(),
|
||||
disconnect: jest.fn()
|
||||
}));
|
||||
|
|
Loading…
Add table
Reference in a new issue