extra-jest
Some extra functions to work with jest testing framework
Requirements
- Node.js ≥ 8.9.0
APIs
NOTE:
xjest
is an alias of moduleextra-jest
jsYaml
is an alias of modulejs-yaml
fsTreeUtils
is an alias of modulefs-tree-utils
xjest.snap.mkfn
declare
This function is used to created xjest.snap.*
functions below.
xjest.snap.*
declare declare declare declare declare
Create jest snapshots but in YAML format.
Features:
xjest.snap.unsafe
dumps JavaScript objects before writing to snapshot.xjest.snap.safe
safely dumps JavaScript objects before writing to snapshot.xjest.snap.pureUnsafe
isxjest.snap.unsafe
without default options.xjest.snap.pureSafe
isxjest.snap.safe
without default options.xjest.snap.noRefs
isxjest.snap.unsafe
with self references.
Default Options:
xjest.setupTeardown.base.createFactory
declare
Creates a TesterFactory<SM, MT>
from a config: Config<SM, MT>
.
Parameters:
config.setup
: A function that runs before main test.config.teardown
: A function that runs after main test.
Returns:
- A
TesterFactory<SM, MT>
is both a namespace and a function, it has the same effect asTesterFactory<SM, MT>::forAsync
. - A
TesterFactory::forAsync
is a function, it creates aTester
fromfn: CalledFunc<SM, MT>
. - A
TesterFactory::forSync
is a function, it creates aTester
fromfn: SyncCalledFunc<SM, MT>
. - A
Tester
can be passed into jesttest
functions as a test function (second argument).
Aliases:
xjest.setupTeardown.createFactory
xjest.setupTeardown.default
xjest.setupTeardown.virtualEnvironment.createFactory
declare
Parameters:
tree
: Specifies directory structure of target directory.container
(optional): Intended target directory, default to random name inos.tmpdir()
folder.
Returns:
Factory::info
: Contains some information that might be useful (seeinterface Info
).Factory::apply
: Takes an async function and returns aTester
.
xjest.snapSpawn.snap
declare
Create a function that creates a snapshot from result of process execution.
Parameters:
fn
: A function that callsspawnSync
.argv
(optional): Additional arguments.options
(optional): Options to pass tospawnSync
.snap
(optional): Snap function to use.
Returns:
- A function that makes snapshots from process execution result.
Aliases:
xjest.snapSpawn.snap.default
xjest.snapSpawn.snap.withCommand
Like xjest.snapSpawn.snap
above but with command: string
as the first parameter instead of fn: SpawnFunc
.