Move waitForUpdate to test-utils

This commit is contained in:
Luke Barnard 2018-05-02 11:19:01 +01:00
parent 3d478c3c3a
commit dc20f32ad7
2 changed files with 21 additions and 20 deletions

View File

@ -26,32 +26,13 @@ import sdk from 'matrix-react-sdk';
import Matrix from 'matrix-js-sdk';
import * as TestUtils from 'test-utils';
const { waitForUpdate } = TestUtils;
const GroupView = sdk.getComponent('structures.GroupView');
const WrappedGroupView = TestUtils.wrapInMatrixClientContext(GroupView);
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() {
let root;
let rootElement;

View File

@ -302,3 +302,23 @@ export function wrapInMatrixClientContext(WrappedComponent) {
}
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;
};
});
}