Merge pull request #1877 from matrix-org/luke/test-room-list

Add tests for RoomList
This commit is contained in:
Luke Barnard 2018-05-04 13:57:57 +01:00 committed by GitHub
commit aa370b3b67
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 316 additions and 21 deletions

View file

@ -74,6 +74,7 @@ export function createTestClient() {
getPushActionsForEvent: sinon.stub(),
getRoom: sinon.stub().returns(mkStubRoom()),
getRooms: sinon.stub().returns([]),
getGroups: sinon.stub().returns([]),
loginFlows: sinon.stub(),
on: sinon.stub(),
removeListener: sinon.stub(),
@ -301,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;
};
});
}