How to use the fast-check.anything function in fast-check

To help you get started, weโ€™ve selected a few fast-check examples, based on popular ways it is used in public projects.

github eemeli / yaml / tests / properties.js View on Github external
test('parse stringified object', () => {
    const key = fc.fullUnicodeString()
    const values = [
      key,
      fc.lorem(1000, false), // words
      fc.lorem(100, true), // sentences
      fc.boolean(),
      fc.integer(),
      fc.double(),
      fc.constantFrom(null, Number.NEGATIVE_INFINITY, Number.POSITIVE_INFINITY)
    ]
    const yamlArbitrary = fc.anything({ key: key, values: values })
    const optionsArbitrary = fc.record(
      {
        keepBlobsInJSON: fc.boolean(),
        keepCstNodes: fc.boolean(),
        keepNodeTypes: fc.boolean(),
        mapAsMap: fc.constant(false),
        merge: fc.boolean(),
        schema: fc.constantFrom('core', 'yaml-1.1') // ignore 'failsafe', 'json'
      },
      { withDeletedKeys: true }
    )

    fc.assert(
      fc.property(yamlArbitrary, optionsArbitrary, (obj, opts) => {
        expect(YAML.parse(YAML.stringify(obj, opts), opts)).toStrictEqual(obj)
      })
github AndersCan / typed-web-workers / tests / TypedWorker.state.spec.ts View on Github external
async function() {
        return fc.assert(
          fc.asyncProperty(
            fc.anything(),
            async (anything: any) => {
              let input = anything
              const output = await PromiseWorker(
                input
              )
              expect(input).toEqual(
                output
              )
            }
          ),
          { numRuns: 10000 }
        )
      },
      10 * 1000 // 10s
github blakeembrey / javascript-stringify / src / index.spec.ts View on Github external
it("should produce string evaluating to the original value", () => {
      fc.assert(
        fc.property(fc.anything(), value => {
          expect(evalValue(stringify(value))).toEqual(value);
        })
      );
    });
  });
github giogonzo / fast-check-io-ts / src / index.ts View on Github external
export function getArbitrary<T extends HasArbitrary>(codec: T): fc.Arbitrary<t.TypeOf<T>> {
  const type: HasArbitrary = codec as any;
  switch (type._tag) {
    case 'UnknownType':
      return fc.anything();
    case 'UndefinedType':
    case 'VoidType':
      return fc.constant(undefined) as any;
    case 'NullType':
      return fc.constant(null) as any;
    case 'StringType':
      return fc.string() as any;
    case 'NumberType':
      return fc.float() as any;
    case 'BooleanType':
      return fc.boolean() as any;
    case 'KeyofType':
      return fc.oneof(...keys(type.keys).map(fc.constant)) as any;
    case 'LiteralType':
      return fc.constant(type.value);
    case 'ArrayType':