ptz-assert
Version:
ptz-assert is an assertion library for creating less verbose tests that wrappers npm assert
43 lines • 1.6 kB
JavaScript
import { deepEqual, equal, notDeepEqual, notEqual, ok, throws } from 'assert';
function notOk(value, errorMsg) {
return ok(!value, errorMsg);
}
function contains(list, item, errorMsg) {
return ok(list.indexOf(item) >= 0, errorMsg);
}
function containsNTimes(list, item, nTimes, errorMsg) {
return equal(list.filter(x => x === item).length, nTimes, errorMsg);
}
function notContains(list, item, errorMsg) {
if (!list)
return;
return notOk(list.indexOf(item) >= 0, errorMsg);
}
function containsFind(list, predicate, errorMsg) {
const index = list.findIndex(predicate);
return ok(index >= 0, errorMsg);
}
function notContainsFind(list, predicate, errorMsg) {
if (!list)
return;
const index = list.findIndex(predicate);
return notOk(index >= 0, errorMsg);
}
function notEmptyString(text, errorMsg) {
if (!text)
throw errorMsg ? errorMsg : 'ERROR_NULL_REQUIRED_STRING';
if (typeof text !== 'string')
throw errorMsg ? errorMsg : 'ERROR_NOT_A_STRING';
}
function notEmptyArray(list, errorMsg) {
if (!list)
throw errorMsg ? errorMsg : 'ERROR_NULL_REQUIRED_ARRAY';
if (list.length < 1)
throw errorMsg ? errorMsg : 'ERROR_EMPTY_REQUIRED_ARRAY';
}
function emptyArray(list, errorMsg) {
if (list && list.length > 0)
throw errorMsg ? errorMsg : 'ERROR_ARRAY_MUST_BE_EMPTY';
}
export { ok, notOk, equal, deepEqual, notEqual, notDeepEqual, throws, contains, containsFind, containsNTimes, notContains, notContainsFind, notEmptyString, notEmptyArray, emptyArray };
//# sourceMappingURL=index.js.map