Skip to content

Instantly share code, notes, and snippets.

Avatar

Dylan Freedman freedmand

View GitHub Profile
@freedmand
freedmand / tester.js
Last active Nov 7, 2018
JavaScript unit testing in under 30 lines
View tester.js
const PASS = ['32']; // green
const FAIL = ['31', '1']; // red, bold
function logStyle(ansiEscapeCodes, text) {
console.log(`\x1b[${ansiEscapeCodes.join(';')}m${text}\x1b[0m`);
}
class Tester {
constructor() {}
@freedmand
freedmand / tester.ts
Last active Nov 3, 2018
Minimal unit testing framework (TypeScript)
View tester.ts
function assert(arg1: any, arg2: any) {
if (arg1 != arg2) throw new Error(`Expected ${arg1} to equal ${arg2}`);
}
const PASS = ['32']; // green
const FAIL = ['31', '1']; // red, bold
function logStyle(codes: string | string[], text: string) {
if (Array.isArray(codes)) codes = codes.join(';');
console.log(`\x1b[${codes}m${text}\x1b[0m`);
You can’t perform that action at this time.