README
ws-jest-env
A testing environment written to work around Jest. Highly recommend to use in tandem with ws-prototype smart objects.
Introduction
ws-jest-env injects a number of help assertions, specs and suites into the global testing scope before each of the jest test files are run. When combined with ws-prototype testing boiler plate can be removed without compremising on test coverage and leaving the developer only conered with the intension under test.
Installing
Add the package to your package.json
yarn add --dev ws-jest-env
Then create a jest setuptestframeworkscriptfile for a globals entry point, and add the file to the jest config. Inside the setup script import all of the ws environment.
import * as env from 'ws-jest-env'
Now all assetions, specs and suites become avalible to all jest test files.
Assertions
isTrue, isFalse
isTrue(candidate);
isDefined, isUndefined
isDefined(candidate);
areSame, areEqual
areEqual([...candidates]);
Specs
exists
exists(candidate);
isAConstructor
isAConstructor(candidate, buildArgs);
requiresOnInit
requiresOnInit(constructor, buildArgs, parameter);
requiresParametersOnInit
requiresParametersOnInit(constructor, buildArgs, parameters);
initalizes
initalizes(constructor, buildArgs, parameter);
initalizesParameters
initalizesParameters(constructor, buildArgs, parameters);
isAFunction
isAFunction(instance, method);
requiresOnCall
requiresOnCall(instance, method, runArgs, parameter, options: { async });
requiresParametersOnCall
requiresParametersOnCall(instance, method, runArgs, parameters, options: { async });
Suites
testClass
testClass combines a number of the above specs to reduce a large amount of general boiler plate of testing that can occur. buildArgs must be a function returning a new instance of the initial argument for construction. (Currently multi argument constructors are not supported)
testClass({
name,
constructor,
buildArgs: () => {},
requiredParams: [],
initParams: [],
dynamicRequire: bool
},
specs : (context) => {});
dynamicRequire overrides the initParams and requiredParams with
Object.keys(buildArgs());
specs should be a function containing detailed specs or further deeper suites.
testMethod
testMethod follows the same patterns as testClass, taking the context of the class the method is attached to.
testMethod({
context,
name,
runArgs: () => [],
requiredParams: [],
initParams: [],
dynamicRequire: bool,
async: bool
},
specs : (context) => {});
Multi-argument method are not currently supported and testMethod requires a context. Keep an eye for this to change.
License
This project is licensed under the MIT License