This package has been deprecated

Author message:

Renamed to stable-function

stable-fn
TypeScript icon, indicating that this package has built-in type declarations

4.0.0 • Public • Published

stable-fn

Ensure a function is stable, meaning the same input always produces the same output

Useful for stress testing functions in your unit tests to make sure their behaviors are consistent.

Install

$ npm install stable-fn

Usage

import stableFunction from 'stable-fn';

stableFunction(() => true);
//=> true

let index = 0;
stableFunction.returnValue(100, () => {
	if (++index === 10) {
		return 'bar';
	}

	return 'foo';
});
//=> 'bar'

API

stableFunction(count?, testFunction)

Returns a boolean whether the output of testFunction was stable.

stableFunction.returnValue(count?, testFunction)

Returns the first differing output of testFunction or the first output if stable.

count

Type: number Default: 1000

Number of times to call the testFunction.

testFunction

Type: function

Function to be tested.

Package Sidebar

Install

npm i stable-fn

Weekly Downloads

11

Version

4.0.0

License

MIT

Unpacked Size

4.53 kB

Total Files

5

Last publish

Collaborators

  • sindresorhus