signal-desktop/libtextsecure/test/helpers_test.js
Scott Nonnenberg b7d56def82 Moves libtextsecure to Typescript
* Starting to work through lint errors

* libsignal-protocol: Update changes for primary repo compatibility

* Step 1: task_with_timeout rename

* Step 2: Apply the changes to TaskWithTimeout.ts

* Step 1: All to-be-converted libtextsecure/*.js files moved

* Step 2: No Typescript errors!

* Get libtextsecure tests passing again

* TSLint errors down to 1

* Compilation succeeds, no lint errors or test failures

* WebSocketResources - update import for case-sensitive filesystems

* Fixes for lint-deps

* Remove unnecessary @ts-ignore

* Fix inability to message your own contact after link

* Add log message for the end of migration 20

* lint fix
2020-04-15 14:45:11 -07:00

32 lines
1,003 B
JavaScript

describe('Helpers', () => {
describe('ArrayBuffer->String conversion', () => {
it('works', () => {
const b = new ArrayBuffer(3);
const a = new Uint8Array(b);
a[0] = 0;
a[1] = 255;
a[2] = 128;
assert.equal(window.textsecure.utils.getString(b), '\x00\xff\x80');
});
});
describe('stringToArrayBuffer', () => {
it('returns ArrayBuffer when passed string', () => {
const anArrayBuffer = new ArrayBuffer(1);
const typedArray = new Uint8Array(anArrayBuffer);
typedArray[0] = 'a'.charCodeAt(0);
assertEqualArrayBuffers(
window.textsecure.utils.stringToArrayBuffer('a'),
anArrayBuffer
);
});
it('throws an error when passed a non string', () => {
const notStringable = [{}, undefined, null, new ArrayBuffer()];
notStringable.forEach(notString => {
assert.throw(() => {
window.textsecure.utils.stringToArrayBuffer(notString);
}, Error);
});
});
});
});