Ensure a function is stable, meaning the same input always produces the same output
MIT License
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.
npm install stable-function
import stableFunction from 'stable-function';
stableFunction(() => true);
//=> true
let index = 0;
stableFunction.returnValue(100, () => {
if (++index === 10) {
return 'bar';
}
return 'foo';
});
//=> 'bar'
Returns a boolean whether the output of testFunction
was stable.
Returns the first differing output of testFunction
or the first output if stable.
Type: number
Default: 1000
The number of times to call the testFunction
.
Type: function
The function to be tested.