Notes/spec-es6/mini_test.js

42 lines
874 B
JavaScript
Raw Normal View History

2020-06-03 17:28:57 +02:00
export function describe(name, cb) {
2020-06-03 17:11:03 +02:00
console.log(`Running ${name}`);
cb();
}
2020-06-03 17:28:57 +02:00
export async function it(name, cb) {
2020-06-03 17:11:03 +02:00
console.log(` Running ${name}`);
cb();
}
let errorCount = 0;
2020-06-03 17:28:57 +02:00
export function expect(val) {
2020-06-03 17:11:03 +02:00
return {
toEqual: comparedVal => {
const jsonVal = JSON.stringify(val);
const comparedJsonVal = JSON.stringify(comparedVal);
if (jsonVal !== comparedJsonVal) {
console.trace("toEqual check failed.");
console.error(`expected: ${comparedJsonVal}`);
console.error(`got: ${jsonVal}`);
errorCount++;
}
}
}
}
2020-06-03 17:28:57 +02:00
export function execute() {
console.log("");
2020-06-03 17:11:03 +02:00
2020-06-03 17:28:57 +02:00
if (errorCount) {
console.log(`!!!${errorCount} tests failed!!!`);
}
else {
console.log("All tests passed!");
}
2020-06-03 17:11:03 +02:00
}