Swap over to Jest, breaking everything
This commit is contained in:
parent
ae010ef649
commit
161a1342b2
8 changed files with 1368 additions and 973 deletions
|
@ -1,13 +0,0 @@
|
|||
// all-tests.js
|
||||
//
|
||||
// Our master test file: uses the webpack require API to find our test files
|
||||
// and run them
|
||||
|
||||
// ideally these unit tests could be run under nodejs rather than in a browser
|
||||
// via karma, but having two separate test frameworks in the same project
|
||||
// seems confusing
|
||||
const unit_tests = require.context('./unit-tests', true, /\.js$/);
|
||||
unit_tests.keys().forEach(unit_tests);
|
||||
|
||||
const app_tests = require.context('./app-tests', true, /\.jsx?$/);
|
||||
app_tests.keys().forEach(app_tests);
|
|
@ -21,15 +21,16 @@ import WebPlatform from '../../src/vector/platform/WebPlatform';
|
|||
import * as sdk from "matrix-react-sdk";
|
||||
import * as jssdk from "matrix-js-sdk";
|
||||
import "../skin-sdk";
|
||||
import "../jest-mocks";
|
||||
import React from "react";
|
||||
import ReactDOM from "react-dom";
|
||||
import ReactTestUtils from "react-dom/test-utils";
|
||||
import expect from "expect";
|
||||
import {makeType} from "matrix-react-sdk/src/utils/TypeUtils";
|
||||
import {ValidatedServerConfig} from "matrix-react-sdk/src/utils/AutoDiscoveryUtils";
|
||||
import {sleep} from "../test-utils";
|
||||
import * as test_utils from "../test-utils";
|
||||
import MockHttpBackend from "matrix-mock-request";
|
||||
import "fake-indexeddb/auto";
|
||||
|
||||
|
||||
const MatrixChat = sdk.getComponent('structures.MatrixChat');
|
|
@ -19,10 +19,10 @@ limitations under the License.
|
|||
import PlatformPeg from 'matrix-react-sdk/src/PlatformPeg';
|
||||
import WebPlatform from '../../src/vector/platform/WebPlatform';
|
||||
import '../skin-sdk';
|
||||
import "../jest-mocks";
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import ReactTestUtils from 'react-dom/test-utils';
|
||||
import expect from 'expect';
|
||||
import MatrixReactTestUtils from 'matrix-react-test-utils';
|
||||
import * as jssdk from 'matrix-js-sdk';
|
||||
import * as sdk from 'matrix-react-sdk';
|
||||
|
@ -36,21 +36,11 @@ import {parseQs, parseQsFromFragment} from '../../src/vector/url_utils';
|
|||
import {makeType} from "matrix-react-sdk/src/utils/TypeUtils";
|
||||
import {ValidatedServerConfig} from "matrix-react-sdk/src/utils/AutoDiscoveryUtils";
|
||||
import {sleep} from "../test-utils";
|
||||
import "fake-indexeddb/auto";
|
||||
|
||||
const DEFAULT_HS_URL='http://my_server';
|
||||
const DEFAULT_IS_URL='http://my_is';
|
||||
|
||||
expect.extend({
|
||||
toStartWith(prefix) {
|
||||
expect.assert(
|
||||
this.actual.startsWith(prefix),
|
||||
'expected %s to start with %s',
|
||||
this.actual, prefix,
|
||||
);
|
||||
return this;
|
||||
}
|
||||
});
|
||||
|
||||
describe('loading:', function() {
|
||||
let parentDiv;
|
||||
let httpBackend;
|
||||
|
@ -65,7 +55,6 @@ describe('loading:', function() {
|
|||
let tokenLoginCompletePromise;
|
||||
|
||||
beforeEach(function() {
|
||||
test_utils.beforeEach(this);
|
||||
httpBackend = new MockHttpBackend();
|
||||
jssdk.request(httpBackend.requestFn);
|
||||
parentDiv = document.createElement('div');
|
||||
|
@ -94,7 +83,7 @@ describe('loading:', function() {
|
|||
expect(MatrixClientPeg.get()).toBe(null);
|
||||
|
||||
// chrome seems to take *ages* to delete the indexeddbs.
|
||||
this.timeout(10000);
|
||||
await sleep(10000);
|
||||
|
||||
// clear the indexeddbs so we can start from a clean slate next time.
|
||||
await Promise.all([
|
14
test/jest-mocks.js
Normal file
14
test/jest-mocks.js
Normal file
|
@ -0,0 +1,14 @@
|
|||
// https://jestjs.io/docs/en/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom
|
||||
Object.defineProperty(window, 'matchMedia', {
|
||||
writable: true,
|
||||
value: jest.fn().mockImplementation(query => ({
|
||||
matches: false,
|
||||
media: query,
|
||||
onchange: null,
|
||||
addListener: jest.fn(), // deprecated
|
||||
removeListener: jest.fn(), // deprecated
|
||||
addEventListener: jest.fn(),
|
||||
removeEventListener: jest.fn(),
|
||||
dispatchEvent: jest.fn(),
|
||||
})),
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue