@outbook/stubs
v1.0.0
Published
Stub functions
Readme
@outbook/stubs
Small stub helpers for tests, event handlers, and functional placeholders.
Install
npm install @outbook/stubsUsage
import {
constant,
noop,
stubArray,
stubObject,
stubString
} from '@outbook/stubs';
const config = stubObject();
const labels = stubArray();
const title = stubString();
const answer = constant(42);
noop();
console.log(config, labels, title, answer());Subpath exports
import { noop, stubNull, stubUndefined } from '@outbook/stubs/functions';
import { alwaysFalse, alwaysTrue } from '@outbook/stubs/predicates';
import { resolves, rejects } from '@outbook/stubs/async';
import { preventDefault, stopPropagation } from '@outbook/stubs/events';API
Functions
noop()andempty(): returnundefined.identity(value): returnsvalue.constant(value): returns a function that always returnsvalue.stubString(): returns''.stubArray(): returns[].stubObject(): returns{}.stubNull(): returnsnull.stubUndefined(): returnsundefined.
Predicates
alwaysTrue()andstubTrue(): returntrue.alwaysFalse()andstubFalse(): returnfalse.
Async
asyncNoop(): resolves withundefined.asyncIdentity(value): resolves withvalue.asyncAlwaysTrue(): resolves withtrue.asyncAlwaysFalse(): resolves withfalse.resolves(value): returns a function that resolves withvalue.rejects(error): returns a function that rejects witherror.
Events
preventDefault(event): callsevent.preventDefault().stopPropagation(event): callsevent.stopPropagation().
