extra-jest v0.0.27
extra-jest
Some extra functions to work with jest testing framework
Requirements
- Node.js ≥ 8.9.0
APIs
NOTE:
xjestis an alias of moduleextra-jestjsYamlis an alias of modulejs-yamlfsTreeUtilsis an alias of modulefs-tree-utils
xjest.snap.mkfn
type DumpFunction<X> = (x: X, options?: jsYaml.DumpOptions) => string
type TestFunction<X> = (x: X, options?: jsYaml.DumpOptions) => () => void
declare function mkfn<X> (fn: DumpFunction<X>, defaultOptions?: jsYaml.DumpOptions): TestFunction<X>This function is used to created xjest.snap.* functions below.
xjest.snap.*
declare function unsafe (x: any, options?: jsYaml.DumpOptions): () => void
declare function safe (x: any, options?: jsYaml.DumpOptions): () => void
declare function pureSafe (x: any, options?: jsYaml.DumpOptions): () => void
declare function pureUnsafe (x: any, options?: jsYaml.DumpOptions): () => void
declare function noRefs (x: any, options?: jsYaml.DumpOptions): () => voidCreate jest snapshots but in YAML format.
Features:
xjest.snap.unsafedumps JavaScript objects before writing to snapshot.xjest.snap.safesafely dumps JavaScript objects before writing to snapshot.xjest.snap.pureUnsafeisxjest.snap.unsafewithout default options.xjest.snap.pureSafeisxjest.snap.safewithout default options.xjest.snap.noRefsisxjest.snap.unsafewith self references.
Default Options:
namespace defaultOptions {
export const skipInvalid = true
export const sortKeys = true
export const noRefs = false
export const noCompatMode = true
}xjest.setupTeardown.base.createFactory
type PromiseFunc<X, Y> = (x: X) => Promise<Y>
type SyncFunc<X, Y> = (x: X) => Y
type SetupFunc<Y> = () => Promise<Y>
type TeardownFunc<X> = (x: X) => Promise<void>
type CalledFunc<X, Y> = PromiseFunc<X, Y>
type SyncCalledFunc<X, Y> = SyncFunc<X, Y>
type Tester = () => Promise<void>
type AsyncTesterFactory<SM, MT> = (fn: CalledFunc<SM, MT>) => Tester
type SyncTesterFactory<SM, MT> = (fn: SyncCalledFunc<SM, MT>) => Tester
interface Config<SY, TX> {
readonly setup: SetupFunc<SY>
readonly teardown: TeardownFunc<TX>
}
type TesterFactory<SM, MT> = AsyncTesterFactory<SM, MT> & {
forAsync: AsyncTesterFactory<SM, MT>,
forSync: SyncTesterFactory<SM, MT>
}
declare function createFactory<SM, MT> (config: Config<SM, MT>): TesterFactory<SM, MT>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::forAsyncis a function, it creates aTesterfromfn: CalledFunc<SM, MT>. - A
TesterFactory::forSyncis a function, it creates aTesterfromfn: SyncCalledFunc<SM, MT>. - A
Testercan be passed into jesttestfunctions as a test function (second argument).
Aliases:
xjest.setupTeardown.createFactoryxjest.setupTeardown.default
xjest.setupTeardown.virtualEnvironment.createFactory
interface Info {
readonly tree: Tree.Write.Node
readonly container: string
readonly previousWorkingDirectory: string
}
interface Factory {
readonly info: Info
readonly apply: base.TesterFactory<Info, void>
}
declare function createFactory (tree: fsTreeUtils.Tree.Write.Node, container?: string): FactoryParameters:
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
type SpawnFunc = (argv: string[], options: SpawnSyncOptions) => SpawnSyncReturns<string | Buffer>
declare function snap (fn: SpawnFunc, argv?: string[], options?: SpawnSyncOptions): () => voidCreate 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.
License
6 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago