mirror of
https://github.com/vector-im/element-web.git
synced 2024-11-15 20:54:59 +08:00
Move waitForUpdate to test-utils
This commit is contained in:
parent
3d478c3c3a
commit
dc20f32ad7
@ -26,32 +26,13 @@ import sdk from 'matrix-react-sdk';
|
|||||||
import Matrix from 'matrix-js-sdk';
|
import Matrix from 'matrix-js-sdk';
|
||||||
|
|
||||||
import * as TestUtils from 'test-utils';
|
import * as TestUtils from 'test-utils';
|
||||||
|
const { waitForUpdate } = TestUtils;
|
||||||
|
|
||||||
const GroupView = sdk.getComponent('structures.GroupView');
|
const GroupView = sdk.getComponent('structures.GroupView');
|
||||||
const WrappedGroupView = TestUtils.wrapInMatrixClientContext(GroupView);
|
const WrappedGroupView = TestUtils.wrapInMatrixClientContext(GroupView);
|
||||||
|
|
||||||
const Spinner = sdk.getComponent('elements.Spinner');
|
const Spinner = sdk.getComponent('elements.Spinner');
|
||||||
|
|
||||||
/**
|
|
||||||
* Call fn before calling componentDidUpdate on a react component instance, inst.
|
|
||||||
* @param {React.Component} inst an instance of a React component.
|
|
||||||
* @returns {Promise} promise that resolves when componentDidUpdate is called on
|
|
||||||
* given component instance.
|
|
||||||
*/
|
|
||||||
function waitForUpdate(inst) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
const cdu = inst.componentDidUpdate;
|
|
||||||
|
|
||||||
inst.componentDidUpdate = (prevProps, prevState, snapshot) => {
|
|
||||||
resolve();
|
|
||||||
|
|
||||||
if (cdu) cdu(prevProps, prevState, snapshot);
|
|
||||||
|
|
||||||
inst.componentDidUpdate = cdu;
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
describe('GroupView', function() {
|
describe('GroupView', function() {
|
||||||
let root;
|
let root;
|
||||||
let rootElement;
|
let rootElement;
|
||||||
|
@ -302,3 +302,23 @@ export function wrapInMatrixClientContext(WrappedComponent) {
|
|||||||
}
|
}
|
||||||
return Wrapper;
|
return Wrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Call fn before calling componentDidUpdate on a react component instance, inst.
|
||||||
|
* @param {React.Component} inst an instance of a React component.
|
||||||
|
* @returns {Promise} promise that resolves when componentDidUpdate is called on
|
||||||
|
* given component instance.
|
||||||
|
*/
|
||||||
|
export function waitForUpdate(inst) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const cdu = inst.componentDidUpdate;
|
||||||
|
|
||||||
|
inst.componentDidUpdate = (prevProps, prevState, snapshot) => {
|
||||||
|
resolve();
|
||||||
|
|
||||||
|
if (cdu) cdu(prevProps, prevState, snapshot);
|
||||||
|
|
||||||
|
inst.componentDidUpdate = cdu;
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user