mulika
Version:
Lightiest & tiniest javascript test tool
41 lines (38 loc) • 1.23 kB
JavaScript
;
const colors = require("colors");
const mulika = {
// Type check...
typeCheck(item) {
let result, item_col;
const type = Object.prototype.toString.call(item.value).slice(8, -1);
item_col = `${item.type.toLowerCase()}`.yellow;
if (type.toLowerCase() === item.type.toLowerCase()) {
result = ` ✔️ Passed type check of typeof ${item_col}`.green;
console.log(result);
} else {
const err = new Error(` ❌ Failed Type Check`);
const stack = err.stack.split("\n");
const line_path = stack[2].split("/");
result = ` ❌ Expected typeof ${item_col}, not ${type.toLowerCase()}
${line_path}`.red;
console.log(result);
}
},
// Testing...
expect(message, value, assertion) {
let value_col;
if (value === assertion) {
console.log(` ✔️ Expected ${message}`.green);
} else {
const err = new Error(`❌ Test Failed`);
const stack = err.stack.split("\n");
const line_path = stack[2].split("/");
value_col = `${value}`.yellow;
console.log(
` ❌ Expected ${message} not ${value_col}
${line_path}`.red
);
}
},
};
module.exports = mulika;