Skip to content

Latest commit

 

History

History
37 lines (34 loc) · 1.19 KB

README.md

File metadata and controls

37 lines (34 loc) · 1.19 KB

function-mocker

A declarative JavaScript function mocker for rapid prototyping.

Maps function calls with args. Function calls can return values, call other functions, with or without context and arguments.

Return a value?

let mock = mocker.mock();
mock.withArgs(someArgs).returns(someReturnValue).done();
let func = mock.build();
func(someArgs) -> returns someReturnValue

Call external functions?

let mockFunc = mock.withArgs(someArgs).callsFunc(afunction).done().build();
mockFunc(someArgs); -> calls afunction

With context?

let mockFunc = mock.withArgs(someArgs).callsFunc(afunction).withCtx(ctx).done().build();
mockFunc(someArgs); -> calls function afunction with "this" set to ctx

With Args?

let mockFunc = mock.withArgs(someArgs).callsFunc(afunction, funcArgs).done().build();
mockFunc(someArgs); -> calls function afunction with funcArgs

Multiple functions?

let mockFunc = mock.withArgs(someArgs).callsFunc(afunction, bfunction).done().build();
mockFunc(someArgs); -> calls afunction, bfunction

Remove a mapping?

mock.remove(someArgs) -> removes mapping for someArgs