chance-generators
Advanced tools
Comparing version 1.17.0 to 1.17.1
@@ -84,7 +84,9 @@ /*global define*/ | ||
mapGenerator.shrink = function (value) { | ||
if (value === lastMappedValue) { | ||
return generator.shrink(lastValue).map(f) | ||
} else { | ||
return generator | ||
if (generator.shrink) { | ||
mapGenerator.shrink = function (value) { | ||
if (value === lastMappedValue) { | ||
return generator.shrink(lastValue).map(f) | ||
} else { | ||
return generator | ||
} | ||
} | ||
@@ -333,11 +335,9 @@ } | ||
that.identity = that.constant = generatorFunction('constant', [], function (data) { | ||
var identityGenerator = generatorFunction('constant', [data], function () { | ||
var constantGenerator = generatorFunction('constant', [data], function () { | ||
return data | ||
}) | ||
identityGenerator.map = function (fn) { | ||
return that.constant(unwrap(fn(data))) | ||
} | ||
installMapFunction(constantGenerator) | ||
return identityGenerator | ||
return constantGenerator | ||
}) | ||
@@ -344,0 +344,0 @@ |
{ | ||
"name": "chance-generators", | ||
"version": "1.17.0", | ||
"version": "1.17.1", | ||
"description": "Random generators based on changejs", | ||
@@ -5,0 +5,0 @@ "main": "lib/chance-generators.js", |
@@ -271,4 +271,5 @@ /*global describe, it*/ | ||
const value = { foo: 'bar' } | ||
const generator = chance.constant(value) | ||
for (var i = 0; i < 5; i += 1) { | ||
expect(chance.constant(value), 'when called', 'to be', value) | ||
expect(generator, 'when called', 'to be', value) | ||
} | ||
@@ -280,2 +281,9 @@ }) | ||
}) | ||
it('supports the map method', () => { | ||
const generator = chance.constant(42).map((value) => { | ||
return chance.natural({ max: value }) | ||
}) | ||
expect(generator, 'when called', 'to be within', 0, 42) | ||
}) | ||
}) | ||
@@ -282,0 +290,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30803
639