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.pull/21833/head
parent
7a821ce9d1
commit
7e6ea192fd
|
@ -1,9 +1,11 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
var sinon = require('sinon');
|
||||||
|
var q = require('q');
|
||||||
|
|
||||||
var peg = require('../src/MatrixClientPeg.js');
|
var peg = require('../src/MatrixClientPeg.js');
|
||||||
var jssdk = require('matrix-js-sdk');
|
var jssdk = require('matrix-js-sdk');
|
||||||
var MatrixEvent = jssdk.MatrixEvent;
|
var MatrixEvent = jssdk.MatrixEvent;
|
||||||
var sinon = require('sinon');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform common actions before each test case, e.g. printing the test case
|
* 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() {
|
module.exports.stubClient = function() {
|
||||||
var sandbox = sinon.sandbox.create();
|
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,
|
// 'sandbox.restore()' doesn't work correctly on inherited methods,
|
||||||
// so we do this for each method
|
// so we do this for each method
|
||||||
var methods = ['get', 'unset', 'replaceUsingUrls',
|
var methods = ['get', 'unset', 'replaceUsingUrls',
|
||||||
|
@ -34,9 +51,7 @@ module.exports.stubClient = function() {
|
||||||
for (var i = 0; i < methods.length; i++) {
|
for (var i = 0; i < methods.length; i++) {
|
||||||
sandbox.stub(peg, methods[i]);
|
sandbox.stub(peg, methods[i]);
|
||||||
}
|
}
|
||||||
|
peg.get.returns(client);
|
||||||
var matrixClientStub = sinon.createStubInstance(jssdk.MatrixClient);
|
|
||||||
peg.get.returns(matrixClientStub);
|
|
||||||
return sandbox;
|
return sandbox;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue