Object Generators

Generate JavaScript objects

qc.object

Generates an object that contains any (random) types.

qc.objectLike(template)

Generates an object that is a clone of the template object, except any values that are of a function type are assumed to be generators and are called with a size parameter.

qc.objectLike({
  hello: "world",
  name: qc.string.matching(/^m(r|s)\. [A-Z][a-z]{3,9}$/)
})(size) // generates:
{
  hello: "world",
  name: "mr. Dasde"
}
qc.objectLike({
  hello: "world"
  name: qc.string.matching(/^m(r|s)\. [A-Z][a-z]{3,9}$/)
})(size) # generates:
{
  hello: "world",
  name: "mr. Dasde"
}
qc.objectLike({
  hello: "world",
  name: qc.string.matching(/^m(r|s)\. [A-Z][a-z]{3,9}$/)
})(size) // generates:
{
  hello: "world",
  name: "mr. Dasde"
}

qc.objectOf(valueGenerator, [keyGenerator])

Generates a random object where the values are produces by the passed valueGenerator and the keys are generated by keyGenerator. keyGenerator defaults to qc.string.