You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-07-31 15:24:23 +03:00
Switch from jasmine to mocha + expect + lolex
Much of this transformation has been done automatically: * add expect import to each file * replace `not.to` with `toNot` * replace `to[Not]Be{Undefined,Null}` with equivalents * replace `jasmine.createSpy(...)` with `except.createSpy`, and `andCallFake` with `andCall` Also: * replace `jasmine.createSpyObj` with manual alternatives * replace `jasmine.Clock` with `lolex`
This commit is contained in:
@ -3,6 +3,8 @@ import 'source-map-support/register';
|
||||
const ContentRepo = require("../../lib/content-repo");
|
||||
const testUtils = require("../test-utils");
|
||||
|
||||
import expect from 'expect';
|
||||
|
||||
describe("ContentRepo", function() {
|
||||
const baseUrl = "https://my.home.server";
|
||||
|
||||
|
@ -1,12 +1,15 @@
|
||||
|
||||
"use strict";
|
||||
import 'source-map-support/register';
|
||||
|
||||
const sdk = require("../..");
|
||||
let Crypto;
|
||||
if (sdk.CRYPTO_ENABLED) {
|
||||
Crypto = require("../../lib/crypto");
|
||||
}
|
||||
|
||||
import expect from 'expect';
|
||||
|
||||
describe("Crypto", function() {
|
||||
if (!sdk.CRYPTO_ENABLED) {
|
||||
return;
|
||||
|
@ -9,6 +9,8 @@ function mockRoomStates(timeline) {
|
||||
timeline._endState = utils.mock(sdk.RoomState, "endState");
|
||||
}
|
||||
|
||||
import expect from 'expect';
|
||||
|
||||
describe("EventTimeline", function() {
|
||||
const roomId = "!foo:bar";
|
||||
const userA = "@alice:bar";
|
||||
@ -76,7 +78,7 @@ describe("EventTimeline", function() {
|
||||
|
||||
expect(function() {
|
||||
timeline.initialiseState(state);
|
||||
}).not.toThrow();
|
||||
}).toNotThrow();
|
||||
timeline.addEvent(event, false);
|
||||
expect(function() {
|
||||
timeline.initialiseState(state);
|
||||
@ -119,7 +121,7 @@ describe("EventTimeline", function() {
|
||||
const next = {b: "b"};
|
||||
expect(function() {
|
||||
timeline.setNeighbouringTimeline(prev, EventTimeline.BACKWARDS);
|
||||
}).not.toThrow();
|
||||
}).toNotThrow();
|
||||
expect(timeline.getNeighbouringTimeline(EventTimeline.BACKWARDS))
|
||||
.toBe(prev);
|
||||
expect(function() {
|
||||
@ -128,7 +130,7 @@ describe("EventTimeline", function() {
|
||||
|
||||
expect(function() {
|
||||
timeline.setNeighbouringTimeline(next, EventTimeline.FORWARDS);
|
||||
}).not.toThrow();
|
||||
}).toNotThrow();
|
||||
expect(timeline.getNeighbouringTimeline(EventTimeline.FORWARDS))
|
||||
.toBe(next);
|
||||
expect(function() {
|
||||
@ -185,14 +187,14 @@ describe("EventTimeline", function() {
|
||||
name: "Old Alice",
|
||||
};
|
||||
timeline.getState(EventTimeline.FORWARDS).getSentinelMember
|
||||
.andCallFake(function(uid) {
|
||||
.andCall(function(uid) {
|
||||
if (uid === userA) {
|
||||
return sentinel;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
timeline.getState(EventTimeline.BACKWARDS).getSentinelMember
|
||||
.andCallFake(function(uid) {
|
||||
.andCall(function(uid) {
|
||||
if (uid === userA) {
|
||||
return oldSentinel;
|
||||
}
|
||||
@ -227,14 +229,14 @@ describe("EventTimeline", function() {
|
||||
name: "Old Alice",
|
||||
};
|
||||
timeline.getState(EventTimeline.FORWARDS).getSentinelMember
|
||||
.andCallFake(function(uid) {
|
||||
.andCall(function(uid) {
|
||||
if (uid === userA) {
|
||||
return sentinel;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
timeline.getState(EventTimeline.BACKWARDS).getSentinelMember
|
||||
.andCallFake(function(uid) {
|
||||
.andCall(function(uid) {
|
||||
if (uid === userA) {
|
||||
return oldSentinel;
|
||||
}
|
||||
@ -279,7 +281,7 @@ describe("EventTimeline", function() {
|
||||
expect(events[1].forwardLooking).toBe(true);
|
||||
|
||||
expect(timeline.getState(EventTimeline.BACKWARDS).setStateEvents).
|
||||
not.toHaveBeenCalled();
|
||||
toNotHaveBeenCalled();
|
||||
});
|
||||
|
||||
|
||||
@ -309,7 +311,7 @@ describe("EventTimeline", function() {
|
||||
expect(events[1].forwardLooking).toBe(false);
|
||||
|
||||
expect(timeline.getState(EventTimeline.FORWARDS).setStateEvents).
|
||||
not.toHaveBeenCalled();
|
||||
toNotHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@ -374,4 +376,3 @@ describe("EventTimeline", function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -4,6 +4,8 @@ const sdk = require("../..");
|
||||
const Filter = sdk.Filter;
|
||||
const utils = require("../test-utils");
|
||||
|
||||
import expect from 'expect';
|
||||
|
||||
describe("Filter", function() {
|
||||
const filterId = "f1lt3ring15g00d4ursoul";
|
||||
const userId = "@sir_arthur_david:humming.tiger";
|
||||
|
@ -23,14 +23,16 @@ const utils = require("../test-utils");
|
||||
const InteractiveAuth = sdk.InteractiveAuth;
|
||||
const MatrixError = sdk.MatrixError;
|
||||
|
||||
import expect from 'expect';
|
||||
|
||||
describe("InteractiveAuth", function() {
|
||||
beforeEach(function() {
|
||||
utils.beforeEach(this); // eslint-disable-line no-invalid-this
|
||||
});
|
||||
|
||||
it("should start an auth stage and complete it", function(done) {
|
||||
const doRequest = jasmine.createSpy('doRequest');
|
||||
const startAuthStage = jasmine.createSpy('startAuthStage');
|
||||
const doRequest = expect.createSpy();
|
||||
const startAuthStage = expect.createSpy();
|
||||
|
||||
const ia = new InteractiveAuth({
|
||||
doRequest: doRequest,
|
||||
@ -52,7 +54,7 @@ describe("InteractiveAuth", function() {
|
||||
});
|
||||
|
||||
// first we expect a call here
|
||||
startAuthStage.andCallFake(function(stage) {
|
||||
startAuthStage.andCall(function(stage) {
|
||||
expect(stage).toEqual("logintype");
|
||||
ia.submitAuthDict({
|
||||
type: "logintype",
|
||||
@ -62,7 +64,7 @@ describe("InteractiveAuth", function() {
|
||||
|
||||
// .. which should trigger a call here
|
||||
const requestRes = {"a": "b"};
|
||||
doRequest.andCallFake(function(authData) {
|
||||
doRequest.andCall(function(authData) {
|
||||
expect(authData).toEqual({
|
||||
session: "sessionId",
|
||||
type: "logintype",
|
||||
@ -79,8 +81,8 @@ describe("InteractiveAuth", function() {
|
||||
});
|
||||
|
||||
it("should make a request if no authdata is provided", function(done) {
|
||||
const doRequest = jasmine.createSpy('doRequest');
|
||||
const startAuthStage = jasmine.createSpy('startAuthStage');
|
||||
const doRequest = expect.createSpy();
|
||||
const startAuthStage = expect.createSpy();
|
||||
|
||||
const ia = new InteractiveAuth({
|
||||
doRequest: doRequest,
|
||||
@ -91,7 +93,7 @@ describe("InteractiveAuth", function() {
|
||||
expect(ia.getStageParams("logintype")).toBe(undefined);
|
||||
|
||||
// first we expect a call to doRequest
|
||||
doRequest.andCallFake(function(authData) {
|
||||
doRequest.andCall(function(authData) {
|
||||
console.log("request1", authData);
|
||||
expect(authData).toBe(null);
|
||||
const err = new MatrixError({
|
||||
@ -109,7 +111,7 @@ describe("InteractiveAuth", function() {
|
||||
|
||||
// .. which should be followed by a call to startAuthStage
|
||||
const requestRes = {"a": "b"};
|
||||
startAuthStage.andCallFake(function(stage) {
|
||||
startAuthStage.andCall(function(stage) {
|
||||
expect(stage).toEqual("logintype");
|
||||
expect(ia.getSessionId()).toEqual("sessionId");
|
||||
expect(ia.getStageParams("logintype")).toEqual({
|
||||
@ -117,7 +119,7 @@ describe("InteractiveAuth", function() {
|
||||
});
|
||||
|
||||
// submitAuthDict should trigger another call to doRequest
|
||||
doRequest.andCallFake(function(authData) {
|
||||
doRequest.andCall(function(authData) {
|
||||
console.log("request2", authData);
|
||||
expect(authData).toEqual({
|
||||
session: "sessionId",
|
||||
|
@ -5,6 +5,9 @@ const sdk = require("../..");
|
||||
const MatrixClient = sdk.MatrixClient;
|
||||
const utils = require("../test-utils");
|
||||
|
||||
import expect from 'expect';
|
||||
import lolex from 'lolex';
|
||||
|
||||
describe("MatrixClient", function() {
|
||||
const userId = "@alice:bar";
|
||||
const identityServerUrl = "https://identity.server";
|
||||
@ -12,6 +15,7 @@ describe("MatrixClient", function() {
|
||||
let client;
|
||||
let store;
|
||||
let scheduler;
|
||||
let clock;
|
||||
|
||||
const KEEP_ALIVE_PATH = "/_matrix/client/versions";
|
||||
|
||||
@ -121,16 +125,16 @@ describe("MatrixClient", function() {
|
||||
|
||||
beforeEach(function() {
|
||||
utils.beforeEach(this); // eslint-disable-line no-invalid-this
|
||||
jasmine.Clock.useMock();
|
||||
scheduler = jasmine.createSpyObj("scheduler", [
|
||||
clock = lolex.install();
|
||||
scheduler = [
|
||||
"getQueueForEvent", "queueEvent", "removeEventFromQueue",
|
||||
"setProcessFunction",
|
||||
]);
|
||||
store = jasmine.createSpyObj("store", [
|
||||
].reduce((r, k) => { r[k] = expect.createSpy(); return r; }, {});
|
||||
store = [
|
||||
"getRoom", "getRooms", "getUser", "getSyncToken", "scrollback",
|
||||
"setSyncToken", "storeEvents", "storeRoom", "storeUser",
|
||||
"getFilterIdByName", "setFilterIdByName", "getFilter", "storeFilter",
|
||||
]);
|
||||
].reduce((r, k) => { r[k] = expect.createSpy(); return r; }, {});
|
||||
client = new MatrixClient({
|
||||
baseUrl: "https://my.home.server",
|
||||
idBaseUrl: identityServerUrl,
|
||||
@ -141,14 +145,14 @@ describe("MatrixClient", function() {
|
||||
userId: userId,
|
||||
});
|
||||
// FIXME: We shouldn't be yanking _http like this.
|
||||
client._http = jasmine.createSpyObj("httpApi", [
|
||||
client._http = [
|
||||
"authedRequest", "authedRequestWithPrefix", "getContentUri",
|
||||
"request", "requestWithPrefix", "uploadContent",
|
||||
]);
|
||||
client._http.authedRequest.andCallFake(httpReq);
|
||||
client._http.authedRequestWithPrefix.andCallFake(httpReq);
|
||||
client._http.requestWithPrefix.andCallFake(httpReq);
|
||||
client._http.request.andCallFake(httpReq);
|
||||
].reduce((r, k) => { r[k] = expect.createSpy(); return r; }, {});
|
||||
client._http.authedRequest.andCall(httpReq);
|
||||
client._http.authedRequestWithPrefix.andCall(httpReq);
|
||||
client._http.requestWithPrefix.andCall(httpReq);
|
||||
client._http.request.andCall(httpReq);
|
||||
|
||||
// set reasonable working defaults
|
||||
acceptKeepalives = true;
|
||||
@ -160,15 +164,16 @@ describe("MatrixClient", function() {
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
clock.uninstall();
|
||||
// need to re-stub the requests with NOPs because there are no guarantees
|
||||
// clients from previous tests will be GC'd before the next test. This
|
||||
// means they may call /events and then fail an expect() which will fail
|
||||
// a DIFFERENT test (pollution between tests!) - we return unresolved
|
||||
// promises to stop the client from continuing to run.
|
||||
client._http.authedRequest.andCallFake(function() {
|
||||
client._http.authedRequest.andCall(function() {
|
||||
return q.defer().promise;
|
||||
});
|
||||
client._http.authedRequestWithPrefix.andCallFake(function() {
|
||||
client._http.authedRequestWithPrefix.andCall(function() {
|
||||
return q.defer().promise;
|
||||
});
|
||||
});
|
||||
@ -195,7 +200,7 @@ describe("MatrixClient", function() {
|
||||
|
||||
describe("getSyncState", function() {
|
||||
it("should return null if the client isn't started", function() {
|
||||
expect(client.getSyncState()).toBeNull();
|
||||
expect(client.getSyncState()).toBe(null);
|
||||
});
|
||||
|
||||
it("should return the same sync state as emitted sync events", function(done) {
|
||||
@ -267,7 +272,7 @@ describe("MatrixClient", function() {
|
||||
if (state === "ERROR" && httpLookups.length > 0) {
|
||||
expect(httpLookups.length).toEqual(2);
|
||||
expect(client.retryImmediately()).toBe(true);
|
||||
jasmine.Clock.tick(1);
|
||||
clock.tick(1);
|
||||
} else if (state === "PREPARED" && httpLookups.length === 0) {
|
||||
client.removeListener("sync", syncListener);
|
||||
done();
|
||||
@ -293,9 +298,9 @@ describe("MatrixClient", function() {
|
||||
expect(client.retryImmediately()).toBe(
|
||||
true, "retryImmediately returned false",
|
||||
);
|
||||
jasmine.Clock.tick(1);
|
||||
clock.tick(1);
|
||||
} else if (state === "RECONNECTING" && httpLookups.length > 0) {
|
||||
jasmine.Clock.tick(10000);
|
||||
clock.tick(10000);
|
||||
} else if (state === "SYNCING" && httpLookups.length === 0) {
|
||||
client.removeListener("sync", syncListener);
|
||||
done();
|
||||
@ -317,7 +322,7 @@ describe("MatrixClient", function() {
|
||||
if (state === "ERROR" && httpLookups.length > 0) {
|
||||
expect(httpLookups.length).toEqual(3);
|
||||
expect(client.retryImmediately()).toBe(true);
|
||||
jasmine.Clock.tick(1);
|
||||
clock.tick(1);
|
||||
} else if (state === "PREPARED" && httpLookups.length === 0) {
|
||||
client.removeListener("sync", syncListener);
|
||||
done();
|
||||
@ -348,7 +353,7 @@ describe("MatrixClient", function() {
|
||||
done();
|
||||
}
|
||||
// standard retry time is 5 to 10 seconds
|
||||
jasmine.Clock.tick(10000);
|
||||
clock.tick(10000);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,8 @@ import 'source-map-support/register';
|
||||
const PushProcessor = require("../../lib/pushprocessor");
|
||||
const utils = require("../test-utils");
|
||||
|
||||
import expect from 'expect';
|
||||
|
||||
describe('NotificationService', function() {
|
||||
const testUserId = "@ali:matrix.org";
|
||||
const testDisplayName = "Alice M";
|
||||
|
@ -4,72 +4,72 @@ import 'source-map-support/register';
|
||||
const callbacks = require("../../lib/realtime-callbacks");
|
||||
const testUtils = require("../test-utils.js");
|
||||
|
||||
import expect from 'expect';
|
||||
import lolex from 'lolex';
|
||||
|
||||
describe("realtime-callbacks", function() {
|
||||
const clock = jasmine.Clock;
|
||||
let fakeDate;
|
||||
let clock;
|
||||
|
||||
function tick(millis) {
|
||||
// make sure we tick the fakedate first, otherwise nothing will happen!
|
||||
fakeDate += millis;
|
||||
clock.tick(millis);
|
||||
}
|
||||
|
||||
beforeEach(function() {
|
||||
testUtils.beforeEach(this); // eslint-disable-line no-invalid-this
|
||||
clock.useMock();
|
||||
fakeDate = Date.now();
|
||||
callbacks.setNow(function() {
|
||||
return fakeDate;
|
||||
});
|
||||
clock = lolex.install();
|
||||
const fakeDate = clock.Date;
|
||||
callbacks.setNow(fakeDate.now.bind(fakeDate));
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
callbacks.setNow();
|
||||
clock.uninstall();
|
||||
});
|
||||
|
||||
describe("setTimeout", function() {
|
||||
it("should call the callback after the timeout", function() {
|
||||
const callback = jasmine.createSpy();
|
||||
const callback = expect.createSpy();
|
||||
callbacks.setTimeout(callback, 100);
|
||||
|
||||
expect(callback).not.toHaveBeenCalled();
|
||||
expect(callback).toNotHaveBeenCalled();
|
||||
tick(100);
|
||||
expect(callback).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
|
||||
it("should default to a zero timeout", function() {
|
||||
const callback = jasmine.createSpy();
|
||||
const callback = expect.createSpy();
|
||||
callbacks.setTimeout(callback);
|
||||
|
||||
expect(callback).not.toHaveBeenCalled();
|
||||
expect(callback).toNotHaveBeenCalled();
|
||||
tick(0);
|
||||
expect(callback).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should pass any parameters to the callback", function() {
|
||||
const callback = jasmine.createSpy();
|
||||
const callback = expect.createSpy();
|
||||
callbacks.setTimeout(callback, 0, "a", "b", "c");
|
||||
tick(0);
|
||||
expect(callback).toHaveBeenCalledWith("a", "b", "c");
|
||||
});
|
||||
|
||||
it("should set 'this' to the global object", function() {
|
||||
const callback = jasmine.createSpy();
|
||||
callback.andCallFake(function() {
|
||||
let passed = false;
|
||||
const callback = function() {
|
||||
expect(this).toBe(global); // eslint-disable-line no-invalid-this
|
||||
expect(this.console).toBeDefined(); // eslint-disable-line no-invalid-this
|
||||
});
|
||||
expect(this.console).toBeTruthy(); // eslint-disable-line no-invalid-this
|
||||
passed = true;
|
||||
};
|
||||
callbacks.setTimeout(callback);
|
||||
tick(0);
|
||||
expect(callback).toHaveBeenCalled();
|
||||
expect(passed).toBe(true);
|
||||
});
|
||||
|
||||
it("should handle timeouts of several seconds", function() {
|
||||
const callback = jasmine.createSpy();
|
||||
const callback = expect.createSpy();
|
||||
callbacks.setTimeout(callback, 2000);
|
||||
|
||||
expect(callback).not.toHaveBeenCalled();
|
||||
expect(callback).toNotHaveBeenCalled();
|
||||
for (let i = 0; i < 4; i++) {
|
||||
tick(500);
|
||||
}
|
||||
@ -77,24 +77,24 @@ describe("realtime-callbacks", function() {
|
||||
});
|
||||
|
||||
it("should call multiple callbacks in the right order", function() {
|
||||
const callback1 = jasmine.createSpy("callback1");
|
||||
const callback2 = jasmine.createSpy("callback2");
|
||||
const callback3 = jasmine.createSpy("callback3");
|
||||
const callback1 = expect.createSpy();
|
||||
const callback2 = expect.createSpy();
|
||||
const callback3 = expect.createSpy();
|
||||
callbacks.setTimeout(callback2, 200);
|
||||
callbacks.setTimeout(callback1, 100);
|
||||
callbacks.setTimeout(callback3, 300);
|
||||
|
||||
expect(callback1).not.toHaveBeenCalled();
|
||||
expect(callback2).not.toHaveBeenCalled();
|
||||
expect(callback3).not.toHaveBeenCalled();
|
||||
expect(callback1).toNotHaveBeenCalled();
|
||||
expect(callback2).toNotHaveBeenCalled();
|
||||
expect(callback3).toNotHaveBeenCalled();
|
||||
tick(100);
|
||||
expect(callback1).toHaveBeenCalled();
|
||||
expect(callback2).not.toHaveBeenCalled();
|
||||
expect(callback3).not.toHaveBeenCalled();
|
||||
expect(callback2).toNotHaveBeenCalled();
|
||||
expect(callback3).toNotHaveBeenCalled();
|
||||
tick(100);
|
||||
expect(callback1).toHaveBeenCalled();
|
||||
expect(callback2).toHaveBeenCalled();
|
||||
expect(callback3).not.toHaveBeenCalled();
|
||||
expect(callback3).toNotHaveBeenCalled();
|
||||
tick(100);
|
||||
expect(callback1).toHaveBeenCalled();
|
||||
expect(callback2).toHaveBeenCalled();
|
||||
@ -102,51 +102,54 @@ describe("realtime-callbacks", function() {
|
||||
});
|
||||
|
||||
it("should treat -ve timeouts the same as a zero timeout", function() {
|
||||
const callback1 = jasmine.createSpy("callback1");
|
||||
const callback2 = jasmine.createSpy("callback2");
|
||||
const callback1 = expect.createSpy();
|
||||
const callback2 = expect.createSpy();
|
||||
|
||||
// check that cb1 is called before cb2
|
||||
callback1.andCallFake(function() {
|
||||
expect(callback2).not.toHaveBeenCalled();
|
||||
callback1.andCall(function() {
|
||||
expect(callback2).toNotHaveBeenCalled();
|
||||
});
|
||||
|
||||
callbacks.setTimeout(callback1);
|
||||
callbacks.setTimeout(callback2, -100);
|
||||
|
||||
expect(callback1).not.toHaveBeenCalled();
|
||||
expect(callback2).not.toHaveBeenCalled();
|
||||
expect(callback1).toNotHaveBeenCalled();
|
||||
expect(callback2).toNotHaveBeenCalled();
|
||||
tick(0);
|
||||
expect(callback1).toHaveBeenCalled();
|
||||
expect(callback2).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should not get confused by chained calls", function() {
|
||||
const callback2 = jasmine.createSpy("callback2");
|
||||
const callback1 = jasmine.createSpy("callback1");
|
||||
callback1.andCallFake(function() {
|
||||
const callback2 = expect.createSpy();
|
||||
const callback1 = expect.createSpy();
|
||||
callback1.andCall(function() {
|
||||
callbacks.setTimeout(callback2, 0);
|
||||
expect(callback2).not.toHaveBeenCalled();
|
||||
expect(callback2).toNotHaveBeenCalled();
|
||||
});
|
||||
|
||||
callbacks.setTimeout(callback1);
|
||||
expect(callback1).not.toHaveBeenCalled();
|
||||
expect(callback2).not.toHaveBeenCalled();
|
||||
expect(callback1).toNotHaveBeenCalled();
|
||||
expect(callback2).toNotHaveBeenCalled();
|
||||
tick(0);
|
||||
expect(callback1).toHaveBeenCalled();
|
||||
// the fake timer won't actually run callbacks registered during
|
||||
// one tick until the next tick.
|
||||
tick(1);
|
||||
expect(callback2).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should be immune to exceptions", function() {
|
||||
const callback1 = jasmine.createSpy("callback1");
|
||||
callback1.andCallFake(function() {
|
||||
const callback1 = expect.createSpy();
|
||||
callback1.andCall(function() {
|
||||
throw new Error("prepare to die");
|
||||
});
|
||||
const callback2 = jasmine.createSpy("callback2");
|
||||
const callback2 = expect.createSpy();
|
||||
callbacks.setTimeout(callback1, 0);
|
||||
callbacks.setTimeout(callback2, 0);
|
||||
|
||||
expect(callback1).not.toHaveBeenCalled();
|
||||
expect(callback2).not.toHaveBeenCalled();
|
||||
expect(callback1).toNotHaveBeenCalled();
|
||||
expect(callback2).toNotHaveBeenCalled();
|
||||
tick(0);
|
||||
expect(callback1).toHaveBeenCalled();
|
||||
expect(callback2).toHaveBeenCalled();
|
||||
@ -155,16 +158,16 @@ describe("realtime-callbacks", function() {
|
||||
|
||||
describe("cancelTimeout", function() {
|
||||
it("should cancel a pending timeout", function() {
|
||||
const callback = jasmine.createSpy();
|
||||
const callback = expect.createSpy();
|
||||
const k = callbacks.setTimeout(callback);
|
||||
callbacks.clearTimeout(k);
|
||||
tick(0);
|
||||
expect(callback).not.toHaveBeenCalled();
|
||||
expect(callback).toNotHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should not affect sooner timeouts", function() {
|
||||
const callback1 = jasmine.createSpy("callback1");
|
||||
const callback2 = jasmine.createSpy("callback2");
|
||||
const callback1 = expect.createSpy();
|
||||
const callback2 = expect.createSpy();
|
||||
|
||||
callbacks.setTimeout(callback1, 100);
|
||||
const k = callbacks.setTimeout(callback2, 200);
|
||||
@ -172,10 +175,10 @@ describe("realtime-callbacks", function() {
|
||||
|
||||
tick(100);
|
||||
expect(callback1).toHaveBeenCalled();
|
||||
expect(callback2).not.toHaveBeenCalled();
|
||||
expect(callback2).toNotHaveBeenCalled();
|
||||
|
||||
tick(150);
|
||||
expect(callback2).not.toHaveBeenCalled();
|
||||
expect(callback2).toNotHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -4,6 +4,8 @@ const sdk = require("../..");
|
||||
const RoomMember = sdk.RoomMember;
|
||||
const utils = require("../test-utils");
|
||||
|
||||
import expect from 'expect';
|
||||
|
||||
describe("RoomMember", function() {
|
||||
const roomId = "!foo:bar";
|
||||
const userA = "@alice:bar";
|
||||
@ -34,7 +36,7 @@ describe("RoomMember", function() {
|
||||
const url = member.getAvatarUrl(hsUrl);
|
||||
// we don't care about how the mxc->http conversion is done, other
|
||||
// than it contains the mxc body.
|
||||
expect(url.indexOf("flibble/wibble")).not.toEqual(-1);
|
||||
expect(url.indexOf("flibble/wibble")).toNotEqual(-1);
|
||||
});
|
||||
|
||||
it("should return an identicon HTTP URL if allowDefault was set and there " +
|
||||
@ -244,9 +246,9 @@ describe("RoomMember", function() {
|
||||
member.setMembershipEvent(joinEvent);
|
||||
expect(member.name).toEqual("Alice"); // prefer displayname
|
||||
member.setMembershipEvent(joinEvent, roomState);
|
||||
expect(member.name).not.toEqual("Alice"); // it should disambig.
|
||||
expect(member.name).toNotEqual("Alice"); // it should disambig.
|
||||
// user_id should be there somewhere
|
||||
expect(member.name.indexOf(userA)).not.toEqual(-1);
|
||||
expect(member.name.indexOf(userA)).toNotEqual(-1);
|
||||
});
|
||||
|
||||
it("should emit 'RoomMember.membership' if the membership changes", function() {
|
||||
|
@ -5,6 +5,8 @@ const RoomState = sdk.RoomState;
|
||||
const RoomMember = sdk.RoomMember;
|
||||
const utils = require("../test-utils");
|
||||
|
||||
import expect from 'expect';
|
||||
|
||||
describe("RoomState", function() {
|
||||
const roomId = "!foo:bar";
|
||||
const userA = "@alice:bar";
|
||||
@ -44,8 +46,8 @@ describe("RoomState", function() {
|
||||
const members = state.getMembers();
|
||||
expect(members.length).toEqual(2);
|
||||
// ordering unimportant
|
||||
expect([userA, userB].indexOf(members[0].userId)).not.toEqual(-1);
|
||||
expect([userA, userB].indexOf(members[1].userId)).not.toEqual(-1);
|
||||
expect([userA, userB].indexOf(members[0].userId)).toNotEqual(-1);
|
||||
expect([userA, userB].indexOf(members[1].userId)).toNotEqual(-1);
|
||||
});
|
||||
});
|
||||
|
||||
@ -55,7 +57,7 @@ describe("RoomState", function() {
|
||||
});
|
||||
|
||||
it("should return a member if they exist", function() {
|
||||
expect(state.getMember(userB)).toBeDefined();
|
||||
expect(state.getMember(userB)).toBeTruthy();
|
||||
});
|
||||
|
||||
it("should return a member which changes as state changes", function() {
|
||||
@ -115,8 +117,8 @@ describe("RoomState", function() {
|
||||
const events = state.getStateEvents("m.room.member");
|
||||
expect(events.length).toEqual(2);
|
||||
// ordering unimportant
|
||||
expect([userA, userB].indexOf(events[0].getStateKey())).not.toEqual(-1);
|
||||
expect([userA, userB].indexOf(events[1].getStateKey())).not.toEqual(-1);
|
||||
expect([userA, userB].indexOf(events[0].getStateKey())).toNotEqual(-1);
|
||||
expect([userA, userB].indexOf(events[1].getStateKey())).toNotEqual(-1);
|
||||
});
|
||||
|
||||
it("should return a single MatrixEvent if a state_key was specified",
|
||||
@ -239,7 +241,7 @@ describe("RoomState", function() {
|
||||
|
||||
// TODO: We do this because we don't DI the RoomMember constructor
|
||||
// so we can't inject a mock :/ so we have to infer.
|
||||
expect(state.members[userC]).toBeDefined();
|
||||
expect(state.members[userC]).toBeTruthy();
|
||||
expect(state.members[userC].powerLevel).toEqual(10);
|
||||
});
|
||||
|
||||
@ -253,7 +255,7 @@ describe("RoomState", function() {
|
||||
});
|
||||
state.setStateEvents([memberEvent]);
|
||||
|
||||
expect(state.members[userA].setMembershipEvent).not.toHaveBeenCalled();
|
||||
expect(state.members[userA].setMembershipEvent).toNotHaveBeenCalled();
|
||||
expect(state.members[userB].setMembershipEvent).toHaveBeenCalledWith(
|
||||
memberEvent, state,
|
||||
);
|
||||
|
@ -8,6 +8,8 @@ const EventStatus = sdk.EventStatus;
|
||||
const EventTimeline = sdk.EventTimeline;
|
||||
const utils = require("../test-utils");
|
||||
|
||||
import expect from 'expect';
|
||||
|
||||
describe("Room", function() {
|
||||
const roomId = "!foo:bar";
|
||||
const userA = "@alice:bar";
|
||||
@ -30,7 +32,7 @@ describe("Room", function() {
|
||||
const hsUrl = "https://my.home.server";
|
||||
|
||||
it("should return the URL from m.room.avatar preferentially", function() {
|
||||
room.currentState.getStateEvents.andCallFake(function(type, key) {
|
||||
room.currentState.getStateEvents.andCall(function(type, key) {
|
||||
if (type === "m.room.avatar" && key === "") {
|
||||
return utils.mkEvent({
|
||||
event: true,
|
||||
@ -47,7 +49,7 @@ describe("Room", function() {
|
||||
const url = room.getAvatarUrl(hsUrl);
|
||||
// we don't care about how the mxc->http conversion is done, other
|
||||
// than it contains the mxc body.
|
||||
expect(url.indexOf("flibble/wibble")).not.toEqual(-1);
|
||||
expect(url.indexOf("flibble/wibble")).toNotEqual(-1);
|
||||
});
|
||||
|
||||
it("should return an identicon HTTP URL if allowDefault was set and there " +
|
||||
@ -79,7 +81,7 @@ describe("Room", function() {
|
||||
});
|
||||
|
||||
it("should return the member from current state", function() {
|
||||
expect(room.getMember(userA)).not.toEqual(null);
|
||||
expect(room.getMember(userA)).toNotEqual(null);
|
||||
});
|
||||
});
|
||||
|
||||
@ -171,7 +173,7 @@ describe("Room", function() {
|
||||
);
|
||||
expect(events[0].forwardLooking).toBe(true);
|
||||
expect(events[1].forwardLooking).toBe(true);
|
||||
expect(room.oldState.setStateEvents).not.toHaveBeenCalled();
|
||||
expect(room.oldState.setStateEvents).toNotHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should synthesize read receipts for the senders of events", function() {
|
||||
@ -180,7 +182,7 @@ describe("Room", function() {
|
||||
membership: "join",
|
||||
name: "Alice",
|
||||
};
|
||||
room.currentState.getSentinelMember.andCallFake(function(uid) {
|
||||
room.currentState.getSentinelMember.andCall(function(uid) {
|
||||
if (uid === userA) {
|
||||
return sentinel;
|
||||
}
|
||||
@ -289,13 +291,13 @@ describe("Room", function() {
|
||||
membership: "join",
|
||||
name: "Old Alice",
|
||||
};
|
||||
room.currentState.getSentinelMember.andCallFake(function(uid) {
|
||||
room.currentState.getSentinelMember.andCall(function(uid) {
|
||||
if (uid === userA) {
|
||||
return sentinel;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
room.oldState.getSentinelMember.andCallFake(function(uid) {
|
||||
room.oldState.getSentinelMember.andCall(function(uid) {
|
||||
if (uid === userA) {
|
||||
return oldSentinel;
|
||||
}
|
||||
@ -328,13 +330,13 @@ describe("Room", function() {
|
||||
membership: "join",
|
||||
name: "Old Alice",
|
||||
};
|
||||
room.currentState.getSentinelMember.andCallFake(function(uid) {
|
||||
room.currentState.getSentinelMember.andCall(function(uid) {
|
||||
if (uid === userA) {
|
||||
return sentinel;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
room.oldState.getSentinelMember.andCallFake(function(uid) {
|
||||
room.oldState.getSentinelMember.andCall(function(uid) {
|
||||
if (uid === userA) {
|
||||
return oldSentinel;
|
||||
}
|
||||
@ -376,7 +378,7 @@ describe("Room", function() {
|
||||
);
|
||||
expect(events[0].forwardLooking).toBe(false);
|
||||
expect(events[1].forwardLooking).toBe(false);
|
||||
expect(room.currentState.setStateEvents).not.toHaveBeenCalled();
|
||||
expect(room.currentState.setStateEvents).toNotHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@ -539,7 +541,7 @@ describe("Room", function() {
|
||||
|
||||
describe("getJoinedMembers", function() {
|
||||
it("should return members whose membership is 'join'", function() {
|
||||
room.currentState.getMembers.andCallFake(function() {
|
||||
room.currentState.getMembers.andCall(function() {
|
||||
return [
|
||||
{ userId: "@alice:bar", membership: "join" },
|
||||
{ userId: "@bob:bar", membership: "invite" },
|
||||
@ -552,7 +554,7 @@ describe("Room", function() {
|
||||
});
|
||||
|
||||
it("should return an empty list if no membership is 'join'", function() {
|
||||
room.currentState.getMembers.andCallFake(function() {
|
||||
room.currentState.getMembers.andCall(function() {
|
||||
return [
|
||||
{ userId: "@bob:bar", membership: "invite" },
|
||||
];
|
||||
@ -647,7 +649,7 @@ describe("Room", function() {
|
||||
|
||||
beforeEach(function() {
|
||||
stateLookup = {};
|
||||
room.currentState.getStateEvents.andCallFake(function(type, key) {
|
||||
room.currentState.getStateEvents.andCall(function(type, key) {
|
||||
if (key === undefined) {
|
||||
const prefix = type + "$";
|
||||
const list = [];
|
||||
@ -664,7 +666,7 @@ describe("Room", function() {
|
||||
return stateLookup[type + "$" + key];
|
||||
}
|
||||
});
|
||||
room.currentState.getMembers.andCallFake(function() {
|
||||
room.currentState.getMembers.andCall(function() {
|
||||
const memberEvents = room.currentState.getStateEvents("m.room.member");
|
||||
const members = [];
|
||||
for (let i = 0; i < memberEvents.length; i++) {
|
||||
@ -679,7 +681,7 @@ describe("Room", function() {
|
||||
}
|
||||
return members;
|
||||
});
|
||||
room.currentState.getMember.andCallFake(function(userId) {
|
||||
room.currentState.getMember.andCall(function(userId) {
|
||||
const memberEvent = room.currentState.getStateEvents(
|
||||
"m.room.member", userId,
|
||||
);
|
||||
@ -713,7 +715,8 @@ describe("Room", function() {
|
||||
room.recalculate(userA);
|
||||
expect(room.currentState.setStateEvents).toHaveBeenCalled();
|
||||
// first call, first arg (which is an array), first element in array
|
||||
const fakeEvent = room.currentState.setStateEvents.calls[0].args[0][0];
|
||||
const fakeEvent = room.currentState.setStateEvents.calls[0].
|
||||
arguments[0][0];
|
||||
expect(fakeEvent.getContent()).toEqual({
|
||||
name: roomName,
|
||||
});
|
||||
@ -732,7 +735,7 @@ describe("Room", function() {
|
||||
];
|
||||
|
||||
room.recalculate(userA);
|
||||
expect(room.currentState.setStateEvents).not.toHaveBeenCalled();
|
||||
expect(room.currentState.setStateEvents).toNotHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@ -768,8 +771,8 @@ describe("Room", function() {
|
||||
addMember(userC);
|
||||
room.recalculate(userA);
|
||||
const name = room.name;
|
||||
expect(name.indexOf(userB)).not.toEqual(-1, name);
|
||||
expect(name.indexOf(userC)).not.toEqual(-1, name);
|
||||
expect(name.indexOf(userB)).toNotEqual(-1, name);
|
||||
expect(name.indexOf(userC)).toNotEqual(-1, name);
|
||||
});
|
||||
|
||||
it("should return the names of members in a public (public join_rules)" +
|
||||
@ -781,8 +784,8 @@ describe("Room", function() {
|
||||
addMember(userC);
|
||||
room.recalculate(userA);
|
||||
const name = room.name;
|
||||
expect(name.indexOf(userB)).not.toEqual(-1, name);
|
||||
expect(name.indexOf(userC)).not.toEqual(-1, name);
|
||||
expect(name.indexOf(userB)).toNotEqual(-1, name);
|
||||
expect(name.indexOf(userC)).toNotEqual(-1, name);
|
||||
});
|
||||
|
||||
it("should show the other user's name for public (public join_rules)" +
|
||||
@ -793,7 +796,7 @@ describe("Room", function() {
|
||||
addMember(userB);
|
||||
room.recalculate(userA);
|
||||
const name = room.name;
|
||||
expect(name.indexOf(userB)).not.toEqual(-1, name);
|
||||
expect(name.indexOf(userB)).toNotEqual(-1, name);
|
||||
});
|
||||
|
||||
it("should show the other user's name for private " +
|
||||
@ -804,7 +807,7 @@ describe("Room", function() {
|
||||
addMember(userB);
|
||||
room.recalculate(userA);
|
||||
const name = room.name;
|
||||
expect(name.indexOf(userB)).not.toEqual(-1, name);
|
||||
expect(name.indexOf(userB)).toNotEqual(-1, name);
|
||||
});
|
||||
|
||||
it("should show the other user's name for private" +
|
||||
@ -814,7 +817,7 @@ describe("Room", function() {
|
||||
addMember(userB);
|
||||
room.recalculate(userA);
|
||||
const name = room.name;
|
||||
expect(name.indexOf(userB)).not.toEqual(-1, name);
|
||||
expect(name.indexOf(userB)).toNotEqual(-1, name);
|
||||
});
|
||||
|
||||
it("should show the room alias if one exists for private " +
|
||||
@ -960,7 +963,7 @@ describe("Room", function() {
|
||||
|
||||
it("should emit an event when a receipt is added",
|
||||
function() {
|
||||
const listener = jasmine.createSpy('spy');
|
||||
const listener = expect.createSpy();
|
||||
room.on("Room.receipt", listener);
|
||||
|
||||
const ts = 13787898424;
|
||||
@ -1131,7 +1134,7 @@ describe("Room", function() {
|
||||
it("should emit Room.tags event when new tags are " +
|
||||
"received on the event stream",
|
||||
function() {
|
||||
const listener = jasmine.createSpy('spy');
|
||||
const listener = expect.createSpy();
|
||||
room.on("Room.tags", listener);
|
||||
|
||||
const tags = { "m.foo": { "order": 0.5 } };
|
||||
|
@ -8,7 +8,11 @@ const MatrixScheduler = sdk.MatrixScheduler;
|
||||
const MatrixError = sdk.MatrixError;
|
||||
const utils = require("../test-utils");
|
||||
|
||||
import expect from 'expect';
|
||||
import lolex from 'lolex';
|
||||
|
||||
describe("MatrixScheduler", function() {
|
||||
let clock;
|
||||
let scheduler;
|
||||
let retryFn;
|
||||
let queueFn;
|
||||
@ -23,7 +27,7 @@ describe("MatrixScheduler", function() {
|
||||
|
||||
beforeEach(function() {
|
||||
utils.beforeEach(this); // eslint-disable-line no-invalid-this
|
||||
jasmine.Clock.useMock();
|
||||
clock = lolex.install();
|
||||
scheduler = new MatrixScheduler(function(ev, attempts, err) {
|
||||
if (retryFn) {
|
||||
return retryFn(ev, attempts, err);
|
||||
@ -40,6 +44,10 @@ describe("MatrixScheduler", function() {
|
||||
defer = q.defer();
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
clock.uninstall();
|
||||
});
|
||||
|
||||
it("should process events in a queue in a FIFO manner", function(done) {
|
||||
retryFn = function() {
|
||||
return 0;
|
||||
@ -99,7 +107,7 @@ describe("MatrixScheduler", function() {
|
||||
defer.reject({});
|
||||
retryDefer.promise.done(function() {
|
||||
expect(procCount).toEqual(1);
|
||||
jasmine.Clock.tick(waitTimeMs);
|
||||
clock.tick(waitTimeMs);
|
||||
expect(procCount).toEqual(2);
|
||||
done();
|
||||
});
|
||||
@ -187,7 +195,7 @@ describe("MatrixScheduler", function() {
|
||||
setTimeout(function() {
|
||||
deferA.resolve({});
|
||||
}, 1000);
|
||||
jasmine.Clock.tick(1000);
|
||||
clock.tick(1000);
|
||||
});
|
||||
|
||||
describe("queueEvent", function() {
|
||||
@ -203,8 +211,8 @@ describe("MatrixScheduler", function() {
|
||||
return "yep";
|
||||
};
|
||||
const prom = scheduler.queueEvent(eventA);
|
||||
expect(prom).toBeDefined();
|
||||
expect(prom.then).toBeDefined();
|
||||
expect(prom).toBeTruthy();
|
||||
expect(prom.then).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
@ -213,14 +221,14 @@ describe("MatrixScheduler", function() {
|
||||
queueFn = function() {
|
||||
return null;
|
||||
};
|
||||
expect(scheduler.getQueueForEvent(eventA)).toBeNull();
|
||||
expect(scheduler.getQueueForEvent(eventA)).toBe(null);
|
||||
});
|
||||
|
||||
it("should return null if the mapped queue doesn't exist", function() {
|
||||
queueFn = function() {
|
||||
return "yep";
|
||||
};
|
||||
expect(scheduler.getQueueForEvent(eventA)).toBeNull();
|
||||
expect(scheduler.getQueueForEvent(eventA)).toBe(null);
|
||||
});
|
||||
|
||||
it("should return a list of events in the queue and modifications to" +
|
||||
|
@ -7,6 +7,7 @@ const TimelineWindow = sdk.TimelineWindow;
|
||||
const TimelineIndex = require("../../lib/timeline-window").TimelineIndex;
|
||||
|
||||
const utils = require("../test-utils");
|
||||
import expect from 'expect';
|
||||
|
||||
const ROOM_ID = "roomId";
|
||||
const USER_ID = "userId";
|
||||
|
@ -4,6 +4,8 @@ const sdk = require("../..");
|
||||
const User = sdk.User;
|
||||
const utils = require("../test-utils");
|
||||
|
||||
import expect from 'expect';
|
||||
|
||||
describe("User", function() {
|
||||
const userId = "@alice:bar";
|
||||
let user;
|
||||
|
@ -3,6 +3,8 @@ import 'source-map-support/register';
|
||||
const utils = require("../../lib/utils");
|
||||
const testUtils = require("../test-utils");
|
||||
|
||||
import expect from 'expect';
|
||||
|
||||
describe("utils", function() {
|
||||
beforeEach(function() {
|
||||
testUtils.beforeEach(this); // eslint-disable-line no-invalid-this
|
||||
@ -133,7 +135,7 @@ describe("utils", function() {
|
||||
utils.checkObjectHasKeys({
|
||||
foo: "bar",
|
||||
}, ["foo"]);
|
||||
}).not.toThrow();
|
||||
}).toNotThrow();
|
||||
});
|
||||
});
|
||||
|
||||
@ -150,7 +152,7 @@ describe("utils", function() {
|
||||
utils.checkObjectHasNoAdditionalKeys({
|
||||
foo: "bar",
|
||||
}, ["foo"]);
|
||||
}).not.toThrow();
|
||||
}).toNotThrow();
|
||||
});
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user