tests is a suite of tools for ease of use for standard testing tools. Things like "verify it exists and is not
null", that you'd want to test against every function, object and string you have.
Importing and Instantiation
Add @flippydisk/tools to your project.
@flippydisk/tools is in the npm registry, so it should be as simple as the
following:
npm i @flippydisk/tools --save-dev
However, if you run into any issues, or simply want a "main" branch version, you can alternatively add this manually
to your package.json under the dependencies{} section:
Once it's in your project, you can either import all of the lang methods, or pick and choose. lang utilities are
individual functions, so there is no instantiation needed.
import * as Tests from '@flippydisk/tools/tests'; // call with Tests.testDefaults()
or as individual items:
import * as Tests from '@flippydisk/tools/tests';
Use
Setup an object in your tests that maps out your class/suites list of modules by types. The Object key should be the
name of the type, and then it should be an array of the names of your modules.
Instantiate a class if need be, or simply use the Suite name as the instance param. Then, run the class or suite
through the Tests.testDefaults() method and it will ensure that all these items exist and are the type you say it
should be.
PASS src/debug/index.spec.js
Debug
√ will provide defaults on initialization (4 ms)
√ and its dependencies should be defined (3 ms)
An example using the Lang suite:
import * as Tests from '@flippydisk/tools/tests';
import * as Lang from '@flippydisk/tools/lang';
const allItems = {
function: [
Lang.filterHTMLTags,
Lang.getPropertySafely,
Lang.getStringSafely,
Lang.isEmptyString,
Lang.isEmptyObject,
Lang.isNull,
Lang.isNullish,
Lang.isNumber,
Lang.isObject,
Lang.isStringy,
Lang.isType,
Lang.isUndefined,
Lang.isValidObject,
],
};
describe('Lang', () => {
Tests.testDefaults(Lang, allItems);
});
Result:
PASS src/lang/index.spec.js
Lang
√ will provide defaults on initialization (4 ms)
√ and its dependencies should be defined (3 ms)
Tests:
There isn't a lot to test here yet, mostly because testDefaults actually runs tests itself, so it's harder to check
against a real 'result'. However, we can at least use it to test itself:
Overview
tests
is a suite of tools for ease of use for standard testing tools. Things like "verify it exists and is not null", that you'd want to test against every function, object and string you have.Importing and Instantiation
Add
@flippydisk/tools
to your project. @flippydisk/tools is in the npm registry, so it should be as simple as the following:npm i @flippydisk/tools --save-dev
However, if you run into any issues, or simply want a "main" branch version, you can alternatively add this manually to your
package.json
under thedependencies{}
section:"@flippydisk/tools": "git+ssh://git@github.com:flippydisk/tools.git"
Once it's in your project, you can either import all of the
lang
methods, or pick and choose.lang
utilities are individual functions, so there is no instantiation needed.import * as Tests from '@flippydisk/tools/tests';
// call with Tests.testDefaults()or as individual items:
Use
Setup an object in your tests that maps out your class/suites list of modules by types. The Object key should be the name of the type, and then it should be an array of the names of your modules.
Instantiate a class if need be, or simply use the Suite name as the
instance
param. Then, run the class or suite through theTests.testDefaults()
method and it will ensure that all these items exist and are thetype
you say it should be.An example using the Debug class:
Result:
An example using the Lang suite:
Result:
Tests:
There isn't a lot to test here yet, mostly because
testDefaults
actually runs tests itself, so it's harder to check against a real 'result'. However, we can at least use it to test itself: