hash-fns
Version:
easily create, assess, and assure hashes within a pit-of-success
32 lines • 1.59 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const test_fns_1 = require("test-fns");
const asHashShake256_1 = require("./asHashShake256");
describe('asHashShake256', () => {
(0, test_fns_1.given)('a basic message and default byte length', () => {
const message = 'hello world';
(0, test_fns_1.then)('it returns a 64-character hex string (32 bytes)', async () => {
const hash = await (0, asHashShake256_1.asHashShake256)(message);
expect(hash).toMatch(/^[a-f0-9]{64}$/);
});
});
(0, test_fns_1.given)('a message and custom output length', () => {
const message = 'hello world';
(0, test_fns_1.then)('it returns a hex string of the correct length', async () => {
const hash16 = await (0, asHashShake256_1.asHashShake256)(message, { bytes: 16 });
expect(hash16).toMatch(/^[a-f0-9]{32}$/); // 16 bytes * 2 hex chars
const hash64 = await (0, asHashShake256_1.asHashShake256)(message, { bytes: 64 });
expect(hash64).toMatch(/^[a-f0-9]{128}$/); // 64 bytes * 2 hex chars
});
});
(0, test_fns_1.given)('two different messages', () => {
const a = 'message one';
const b = 'message two';
(0, test_fns_1.then)('they produce different hashes', async () => {
const ha = await (0, asHashShake256_1.asHashShake256)(a);
const hb = await (0, asHashShake256_1.asHashShake256)(b);
expect(ha).not.toBe(hb);
});
});
});
//# sourceMappingURL=asHashShake256.test.js.map