Stub out the matrix client

This commit is contained in:
Richard van der Hoff 2016-03-28 22:59:34 +01:00
parent 7e1e2347b5
commit 5f3b82a767
3 changed files with 68 additions and 10 deletions

36
test/test-utils.js Normal file
View file

@ -0,0 +1,36 @@
"use strict";
var peg = require('../src/MatrixClientPeg.js');
var jssdk = require('matrix-js-sdk');
var sinon = require('sinon');
/**
* Stub out the MatrixClient, and configure the MatrixClientPeg object to
* return it when get() is called.
*/
module.exports.stubClient = function() {
var pegstub = sinon.stub(peg);
var matrixClientStub = sinon.createStubInstance(jssdk.MatrixClient);
pegstub.get.returns(matrixClientStub);
}
/**
* make the test fail, with the given exception
*
* <p>This is useful for use with integration tests which use asyncronous
* methods: it can be added as a 'catch' handler in a promise chain.
*
* @param {Error} error exception to be reported
*
* @example
* it("should not throw", function(done) {
* asynchronousMethod().then(function() {
* // some tests
* }).catch(utils.failTest).done(done);
* });
*/
module.exports.failTest = function(error) {
expect(error.stack).toBe(null);
};