Stub out the matrix client

pull/21833/head
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

View File

@ -7,7 +7,6 @@ var path = require('path');
* the easiest way to load our dependencies from node_modules.
*
* TODO:
* - how do we stub out the js-sdk
* - can we run one test at a time
* - can we can we run under phantomjs/jsdom?
* - write junit out
@ -20,7 +19,14 @@ module.exports = function (config) {
// list of files / patterns to load in the browser
files: [
'test/tests.js'
'test/tests.js',
],
// list of files to exclude
// (this doesn't work, and I don't know why - we still rerun the tests
// when lockfiles are created)
exclude: [
'**/.#*'
],
// preprocess matching files before serving them to the browser
@ -70,13 +76,21 @@ module.exports = function (config) {
module: {
loaders: [
{ test: /\.json$/, loader: "json" },
{ test: /\.js$/, loader: "babel",
include: [path.resolve('./src'),
path.resolve('./test'),
],
query: {
presets: ['react', 'es2015']
},
{
// disable 'require' and 'define' for sinon, per
// https://github.com/webpack/webpack/issues/304#issuecomment-170883329
test: /sinon\/pkg\/sinon\.js/,
// TODO: use 'query'?
loader: 'imports?define=>false,require=>false',
},
{
test: /\.js$/, loader: "babel",
include: [path.resolve('./src'),
path.resolve('./test'),
],
query: {
presets: ['react', 'es2015']
},
},
],
noParse: [
@ -91,6 +105,7 @@ module.exports = function (config) {
resolve: {
alias: {
'matrix-react-sdk': path.resolve('src/index.js'),
'sinon': 'sinon/pkg/sinon.js',
},
},
devtool: 'inline-source-map',

View File

@ -3,14 +3,21 @@ var TestUtils = require('react-addons-test-utils');
var expect = require('expect');
var sdk = require('matrix-react-sdk');
var MatrixChat;
var test_utils = require('../../test-utils');
var peg = require('../../../src/MatrixClientPeg.js');
var q = require('q');
describe('MatrixChat', function () {
var MatrixChat;
before(function() {
test_utils.stubClient();
MatrixChat = sdk.getComponent('structures.MatrixChat');
});
it('gives a login panel by default', function () {
peg.get().loginFlows.returns(q({}));
var res = TestUtils.renderIntoDocument(
<MatrixChat config={{}}/>
);

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);
};