From 7e6ea192fd41f35b4d7164ee9e05fecd69059980 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Fri, 8 Apr 2016 14:50:04 +0100 Subject: [PATCH] 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. --- test/test-utils.js | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/test/test-utils.js b/test/test-utils.js index 956c3c15b0..a077722678 100644 --- a/test/test-utils.js +++ b/test/test-utils.js @@ -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; }