26 test failures to go :D

This commit is contained in:
Michael Telatynski 2019-12-16 11:55:01 +00:00
parent 6ad31fe023
commit 0041dae664
7 changed files with 70 additions and 10 deletions

View file

@ -78,8 +78,9 @@ describe('MessagePanel', function() {
client.credentials = {userId: '@me:here'};
// HACK: We assume all settings want to be disabled
SettingsStore.getValue = jest.fn().returns(false);
SettingsStore.getValue.withArgs('showDisplaynameChanges').returns(true);
SettingsStore.getValue = jest.fn((arg) => {
return arg === "showDisplaynameChanges";
});
// This option clobbers the duration of all animations to be 1ms
// which makes unit testing a lot simpler (the animation doesn't

View file

@ -69,7 +69,7 @@ describe('Login', function() {
});
it('should show form without change server link when custom URLs disabled', function() {
jest.spyOn(SdkConfig, "get").returns({
jest.spyOn(SdkConfig, "get").mockReturnValue({
disable_custom_urls: true,
});

View file

@ -58,7 +58,7 @@ describe('Registration', function() {
});
it('should show form when custom URLs disabled', function() {
jest.spyOn(SdkConfig, "get").returns({
jest.spyOn(SdkConfig, "get").mockReturnValue({
disable_custom_urls: true,
});

View file

@ -27,7 +27,7 @@ describe('RoomViewStore', function() {
});
it('can be used to view a room by alias and join', function(done) {
peg.get().getRoomIdForAlias.returns(Promise.resolve({room_id: "!randomcharacters:aser.ver"}));
peg.get().getRoomIdForAlias.mockResolvedValue({room_id: "!randomcharacters:aser.ver"});
peg.get().joinRoom = (roomAddress) => {
expect(roomAddress).toBe("#somealias2:aser.ver");
done();

View file

@ -16,7 +16,27 @@ limitations under the License.
"use strict";
import SubtleCrypto from 'subtle';
import webcrypto from "node-webcrypto-shim";
import {TextEncoder} from "util";
import crypto from "crypto";
function getRandomValues(buf) {
if (!(buf instanceof Uint8Array)) {
throw new TypeError('expected Uint8Array');
}
if (buf.length > 65536) {
const e = new Error();
e.code = 22;
e.message = 'Failed to execute \'getRandomValues\' on \'Crypto\': The ' +
'ArrayBufferView\'s byte length (' + buf.length + ') exceeds the ' +
'number of bytes of entropy available via this API (65536).';
e.name = 'QuotaExceededError';
throw e;
}
const bytes = crypto.randomBytes(buf.length);
buf.set(bytes);
return buf;
}
const TEST_VECTORS=[
[
@ -66,7 +86,7 @@ describe('MegolmExportEncryption', function() {
let MegolmExportEncryption;
beforeAll(() => {
window.crypto = { subtle: SubtleCrypto };
window.crypto = { ...webcrypto, getRandomValues };
MegolmExportEncryption = require("../../src/utils/MegolmExportEncryption");
});