You've already forked matrix-react-sdk
mirror of
https://github.com/matrix-org/matrix-react-sdk.git
synced 2025-07-30 02:21:17 +03:00
Build our own stub MatrixClient for the tests
It turns out that a bunch of things rely on MatrixClient methods to return promises rather than undefined. Rather than having to undo half the work done by sinon.createStubInstance, just build our own object with as many methods as we need stubbed out.
This commit is contained in:
@ -1,9 +1,11 @@
|
||||
"use strict";
|
||||
|
||||
var sinon = require('sinon');
|
||||
var q = require('q');
|
||||
|
||||
var peg = require('../src/MatrixClientPeg.js');
|
||||
var jssdk = require('matrix-js-sdk');
|
||||
var MatrixEvent = jssdk.MatrixEvent;
|
||||
var sinon = require('sinon');
|
||||
|
||||
/**
|
||||
* Perform common actions before each test case, e.g. printing the test case
|
||||
@ -27,6 +29,21 @@ module.exports.beforeEach = function(context) {
|
||||
module.exports.stubClient = function() {
|
||||
var sandbox = sinon.sandbox.create();
|
||||
|
||||
var client = {
|
||||
getHomeserverUrl: sinon.stub(),
|
||||
getIdentityServerUrl: sinon.stub(),
|
||||
|
||||
getPushActionsForEvent: sinon.stub(),
|
||||
getRoom: sinon.stub(),
|
||||
loginFlows: sinon.stub(),
|
||||
on: sinon.stub(),
|
||||
|
||||
paginateEventTimeline: sinon.stub().returns(q()),
|
||||
sendReadReceipt: sinon.stub().returns(q()),
|
||||
};
|
||||
|
||||
// create the peg
|
||||
|
||||
// 'sandbox.restore()' doesn't work correctly on inherited methods,
|
||||
// so we do this for each method
|
||||
var methods = ['get', 'unset', 'replaceUsingUrls',
|
||||
@ -34,9 +51,7 @@ module.exports.stubClient = function() {
|
||||
for (var i = 0; i < methods.length; i++) {
|
||||
sandbox.stub(peg, methods[i]);
|
||||
}
|
||||
|
||||
var matrixClientStub = sinon.createStubInstance(jssdk.MatrixClient);
|
||||
peg.get.returns(matrixClientStub);
|
||||
peg.get.returns(client);
|
||||
return sandbox;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user