Skip to content

Commit

Permalink
added automatic fail test, release 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
capnajax committed Jul 27, 2023
1 parent e8847f7 commit cac12e7
Show file tree
Hide file tree
Showing 4 changed files with 180 additions and 118 deletions.
83 changes: 49 additions & 34 deletions TestBattery.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ const operators = (() => {
( a && a.valueOf && a.valueOf(a) === false) )
},
falsey: a => !a,
fail: () => false,
file: a => {
let file = Array.isArray(a)
? path.join.apply(null, a)
Expand Down Expand Up @@ -418,13 +419,27 @@ class TestBattery {
});
}

/**
* @method fail
* Tests that always fails
* @param {*} result the result to test.
* @param {string} should an error message. Can include parameterizations to
* be filled in with `format`.
* @param {...any} [params] parameters for the error message
*/
fail(result, should, ...params) {
this.doTest(function() {
return false;
}, result, should, params);
}

/**
* @method isArray
* Tests if `result` is an array.
* @param {*} result the result to test. If `result` is a promise, it'll test
* the value that the promise resolves with.
* @param {string} should an error message. Can include parameterizations to be
* filled in with `format`.
* @param {string} should an error message. Can include parameterizations to
* be filled in with `format`.
* @param {...any} [params] parameters for the error message
*/
isArray(result, should, ...params) {
Expand All @@ -439,8 +454,8 @@ class TestBattery {
* Boolean objects.
* @param {*} result the result to test. If `result` is a promise, it'll test
* the value that the promise resolves with.
* @param {string} should an error message. Can include parameterizations to be
* filled in with `format`.
* @param {string} should an error message. Can include parameterizations to
* be filled in with `format`.
* @param {...any} [params] parameters for the error message
*/
isBoolean(result, should, ...params) {
Expand All @@ -456,8 +471,8 @@ class TestBattery {
* it. All other types will always fail the test.
* @param {*} result the result to test. If `result` is a promise, it'll test
* the value that the promise resolves with.
* @param {string} should an error message. Can include parameterizations to be
* filled in with `format`.
* @param {string} should an error message. Can include parameterizations to
* be filled in with `format`.
* @param {...any} [params] parameters for the error message
*/
isDirectory(result, should, ...params) {
Expand All @@ -483,8 +498,8 @@ class TestBattery {
* Tests if `result` is an empty array.
* @param {*} result the result to test. If `result` is a promise, it'll test
* the value that the promise resolves with.
* @param {string} should an error message. Can include parameterizations to be
* filled in with `format`.
* @param {string} should an error message. Can include parameterizations to
* be filled in with `format`.
* @param {...any} [params] parameters for the error message
*/
isEmptyArray(result, should, ...params) {
Expand All @@ -498,8 +513,8 @@ class TestBattery {
* Tests if `result` is an empty object that is not an array.
* @param {*} result the result to test. If `result` is a promise, it'll test
* the value that the promise resolves with.
* @param {string} should an error message. Can include parameterizations to be
* filled in with `format`.
* @param {string} should an error message. Can include parameterizations to
* be filled in with `format`.
* @param {...any} [params] parameters for the error message
*/
isEmptyObject(result, should, ...params) {
Expand All @@ -515,8 +530,8 @@ class TestBattery {
* String objects.
* @param {*} result the result to test. If `result` is a promise, it'll test
* the value that the promise resolves with.
* @param {string} should an error message. Can include parameterizations to be
* filled in with `format`.
* @param {string} should an error message. Can include parameterizations to
* be filled in with `format`.
* @param {...any} [params] parameters for the error message
*/
isEmptyString(result, should, ...params) {
Expand All @@ -534,8 +549,8 @@ class TestBattery {
* the value that the promise resolves with.
* @param {*} a the second value to test. If `result` is a promise, it'll test
* the value that the promise resolves with.
* @param {string} should an error message. Can include parameterizations to be
* filled in with `format`.
* @param {string} should an error message. Can include parameterizations to
* be filled in with `format`.
* @param {...any} [params] parameters for the error message
*/
isEqual(a, b, should, ...params) {
Expand All @@ -551,8 +566,8 @@ class TestBattery {
* just evaluate to false.
* @param {*} result the result to test. If `result` is a promise, it'll test
* the value that the promise resolves with.
* @param {string} should an error message. Can include parameterizations to be
* filled in with `format`.
* @param {string} should an error message. Can include parameterizations to
* be filled in with `format`.
* @param {...any} [params] parameters for the error message
*/
isFalse(result, should, ...params) {
Expand All @@ -568,8 +583,8 @@ class TestBattery {
* added a bang to it. (e.g. !null === true)
* @param {*} result the result to test. If `result` is a promise, it'll test
* the value that the promise resolves with.
* @param {string} should an error message. Can include parameterizations to be
* filled in with `format`.
* @param {string} should an error message. Can include parameterizations to
* be filled in with `format`.
* @param {...any} [params] parameters for the error message
*/
isFalsey(result, should, ...params) {
Expand All @@ -585,8 +600,8 @@ class TestBattery {
* it. All other types will always fail the test.
* @param {*} result the result to test. If `result` is a promise, it'll test
* the value that the promise resolves with.
* @param {string} should an error message. Can include parameterizations to be
* filled in with `format`.
* @param {string} should an error message. Can include parameterizations to
* be filled in with `format`.
* @param {...any} [params] parameters for the error message
*/
isFile(result, should, ...params) {
Expand All @@ -612,8 +627,8 @@ class TestBattery {
* Tests if `result` is `null` or `undefined`.
* @param {*} result the result to test. If `result` is a promise, it'll test
* the value that the promise resolves with.
* @param {string} should an error message. Can include parameterizations to be
* filled in with `format`.
* @param {string} should an error message. Can include parameterizations to
* be filled in with `format`.
* @param {...any} [params] parameters for the error message
*/
isNil(result, should, ...params) {
Expand All @@ -627,8 +642,8 @@ class TestBattery {
* Tests if `result` is `null`.
* @param {*} result the result to test. If `result` is a promise, it'll test
* the value that the promise resolves with.
* @param {string} should an error message. Can include parameterizations to be
* filled in with `format`.
* @param {string} should an error message. Can include parameterizations to
* be filled in with `format`.
* @param {...any} [params] parameters for the error message
*/
isNull(result, should, ...params) {
Expand All @@ -645,8 +660,8 @@ class TestBattery {
* the value that the promise resolves with.
* @param {*} a the second value to test. If `result` is a promise, it'll test
* the value that the promise resolves with.
* @param {string} should an error message. Can include parameterizations to be
* filled in with `format`.
* @param {string} should an error message. Can include parameterizations to
* be filled in with `format`.
* @param {...any} [params] parameters for the error message
*/
isStrictlyEqual(a, b, should, ...params) {
Expand All @@ -661,8 +676,8 @@ class TestBattery {
* objects.
* @param {*} result the result to test. If `result` is a promise, it'll test
* the value that the promise resolves with.
* @param {string} should an error message. Can include parameterizations to be
* filled in with `format`.
* @param {string} should an error message. Can include parameterizations to
* be filled in with `format`.
* @param {...any} [params] parameters for the error message
*/
isString(result, should, ...params) {
Expand All @@ -678,8 +693,8 @@ class TestBattery {
* just evaluate to true.
* @param {*} result the result to test. If `result` is a promise, it'll test
* the value that the promise resolves with.
* @param {string} should an error message. Can include parameterizations to be
* filled in with `format`.
* @param {string} should an error message. Can include parameterizations to
* be filled in with `format`.
* @param {...any} [params] parameters for the error message
*/
isTrue(result, should, ...params) {
Expand All @@ -695,8 +710,8 @@ class TestBattery {
* added a double bang to it. (e.g. !!'hi' === true)
* @param {*} result the result to test. If `result` is a promise, it'll test
* the value that the promise resolves with.
* @param {string} should an error message. Can include parameterizations to be
* filled in with `format`.
* @param {string} should an error message. Can include parameterizations to
* be filled in with `format`.
* @param {...any} [params] parameters for the error message
*/
isTruthy(result, should, ...params) {
Expand All @@ -710,8 +725,8 @@ class TestBattery {
* Tests if `result` is an `undefined`.
* @param {*} result the result to test. If `result` is a promise, it'll test
* the value that the promise resolves with.
* @param {string} should an error message. Can include parameterizations to be
* filled in with `format`.
* @param {string} should an error message. Can include parameterizations to
* be filled in with `format`.
* @param {...any} [params] parameters for the error message
*/
isUndefined(result, should, ...params) {
Expand Down
Loading

0 comments on commit cac12e7

Please sign in to comment.