escss-estest
100% function coverage makes your life easier.
Installation
npm install escss-estest
Usage
// operator mode
* esTest(1, '<', 5)
* esTest(5, '>', 1)
* esTest(1, '<=', 5)
* esTest(5, '>=', 1)
* esTest(1, '!==', 2)
* esTest(1, '===', 1)
* esTest(1, '===', 100) // error
* esTest(1, '===', 100, 'foo') // error & message
*
* // type mode
* esTest(1, 'number')
* esTest(1n, 'bigint')
* esTest('foo', 'string')
* esTest(true, 'boolean')
* esTest([], 'array')
* esTest({}, 'object')
* esTest(NaN, 'NaN')
* esTest(null, 'null')
* esTest(undefined, 'undefined')
* esTest(Symbol(), 'symbol')
* esTest(function () {}, 'function')
* esTest(1, 'object') // error
* esTest(1, 'object', 'foo') // error & message
Examples
function sum(a, b) {
{
esTest(a, 'number')
esTest(b, 'number', 'should be number type')
}
return a + b
}
async function getData() {
const url = "https://jsonplaceholder.typicode.com/todos/1";
const response = await fetch(url);
const json = await response.json();
{
esTest(json.completed, 'boolean')
esTest(json.id, 'number')
esTest(json.title, 'string')
esTest(json.userId, 'number')
}
console.log(json);
}
License
Dual Licensing( Commercial or AGPL 3.0 ), see here to know more