24 lines
813 B
JavaScript

import { ab2str, str2ab, exportedKeyToPem, pemToKey, genKey } from '../src/public/ecc.js';
describe('ecc.js functions', () => {
// Test ab2str
it('should convert ArrayBuffer to string', () => {
const buffer = new ArrayBuffer(5);
const view = new Uint8Array(buffer);
view.set([72, 101, 108, 108, 111]); // ASCII values for "Hello"
const result = ab2str(buffer);
expect(result).toBe("Hello");
});
// Test str2ab
it('should convert string to ArrayBuffer', () => {
const str = "Hello";
const result = str2ab(str);
const expectedBuffer = new ArrayBuffer(5);
const expectedView = new Uint8Array(expectedBuffer);
expectedView.set([72, 101, 108, 108, 111]);
expect(result).toEqual(expectedBuffer);
});
});