stable-fn
Ensure a function is stable, meaning the same input always produces the same output
Last updated 2 years ago by sindresorhus .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install stable-fn 
SYNC missed versions from official npm registry.

stable-fn Build Status

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

const stableFn = require('stable-fn');

stableFn(() => true);
//=> true

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

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

API

stableFn([count], fn)

Returns a boolean whether the output of fn was stable.

stableFn.returnValue([count], fn)

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

count

Type: number Default: 1000

Number of times to call the fn.

fn

Type: function

Function to be tested.

License

MIT © Sindre Sorhus

Current Tags

  • 2.0.0                                ...           latest (2 years ago)

2 Versions

  • 2.0.0                                ...           2 years ago
  • 1.0.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 2
Dependencies (0)
None
Dev Dependencies (3)

Copyright 2014 - 2017 © taobao.org |