How to use the fast-check.boolean 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.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sindresorhus / query-string / test / properties.js View on Github external
// - value must be one of:
// --> any unicode string
// --> null
// --> array containing values defined above (at least two items)
const queryParamsArbitrary = fastCheck.dictionary(
	fastCheck.fullUnicodeString(1, 10),
	fastCheck.oneof(
		fastCheck.fullUnicodeString(),
		fastCheck.constant(null),
		fastCheck.array(fastCheck.oneof(fastCheck.fullUnicodeString(), fastCheck.constant(null)), 2, 10)
	)
);

const optionsArbitrary = fastCheck.record({
	arrayFormat: fastCheck.constantFrom('bracket', 'index', 'none'),
	strict: fastCheck.boolean(),
	encode: fastCheck.constant(true),
	sort: fastCheck.constant(false)
}, {withDeletedKeys: true});

test('should read correctly from stringified query params', t => {
	t.notThrows(() => {
		fastCheck.assert(
			fastCheck.property(
				queryParamsArbitrary,
				optionsArbitrary,
				(object, options) => deepEqual(queryString.parse(queryString.stringify(object, options), options), object)
			)
		);
	});
});
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 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 dubzzz / fast-check / example / 005-race / todolist / main.spec.tsx View on Github external
it('should detect potential issues with the TodoList', async () =>
    await fc.assert(
      fc
        .asyncProperty(
          fc.scheduler({ act }),
          TodoListCommands,
          fc.set(
            fc.record({ id: fc.hexaString(8, 8), label: fc.string(), checked: fc.boolean() }),
            (a, b) => a.id === b.id
          ),
          fc.infiniteStream(fc.boolean()),
          async (s, commands, initialTodos, allFailures) => {
            const { mockedApi, expectedTodos } = mockApi(s, initialTodos, allFailures);

            // Execute all the commands
            const wrapper = render();
            await fc.scheduledModelRun(s, () => ({ model: { todos: [], wrapper }, real: {} }), commands);

            // Check the final state (no more items should be loading)
            expect(
              sortTodos(
                (await listTodos(wrapper)).map(t => ({ label: t.label, checked: t.checked, loading: t.loading }))
              )
            ).toEqual(sortTodos(expectedTodos().map(t => ({ label: t.label, checked: t.checked, loading: false }))));
github dubzzz / fast-check / example / 005-race / todolist / main.spec.tsx View on Github external
it('should detect potential issues with the TodoList', async () =>
    await fc.assert(
      fc
        .asyncProperty(
          fc.scheduler({ act }),
          TodoListCommands,
          fc.set(
            fc.record({ id: fc.hexaString(8, 8), label: fc.string(), checked: fc.boolean() }),
            (a, b) => a.id === b.id
          ),
          fc.infiniteStream(fc.boolean()),
          async (s, commands, initialTodos, allFailures) => {
            const { mockedApi, expectedTodos } = mockApi(s, initialTodos, allFailures);

            // Execute all the commands
            const wrapper = render();
            await fc.scheduledModelRun(s, () => ({ model: { todos: [], wrapper }, real: {} }), commands);

            // Check the final state (no more items should be loading)
            expect(
              sortTodos(
                (await listTodos(wrapper)).map(t => ({ label: t.label, checked: t.checked, loading: t.loading }))
              )
            ).toEqual(sortTodos(expectedTodos().map(t => ({ label: t.label, checked: t.checked, loading: false }))));
          }
        )
        .beforeEach(async () => {
github aiden / rpc_ts / src / protocol / grpc_web / __tests__ / client_server.it.ts View on Github external
it('successful unary call', async () => {
      await fc.assert(
        fc.asyncProperty(
          fc.record({
            method: lowerCamelCase(),
            requestContext: context(),
            responseContext: context(),
            useCompression: fc.boolean(),
            request: fc.dictionary(fc.string(), fc.jsonObject()),
            useRequestFunction: fc.boolean(),
          }),
          async arb => {
            const app = express();
            const handler: ModuleRpcServer.ServiceHandlerFor<
              typeof unaryServiceDefinition,
              any
            > = {
              async unary(request, requestContext) {
                return {
                  fooRequest: request,
                  barRequestContext: requestContext,
                };
              },
            };
            app.use(
              '/api',
github aiden / rpc_ts / src / protocol / grpc_web / __tests__ / client_server.it.ts View on Github external
it('successful server-stream call', async () => {
      await fc.assert(
        fc.asyncProperty(
          fc.record({
            method: lowerCamelCase(),
            requestContext: context(),
            responseContext: context(),
            useCompression: fc.boolean(),
            request: fc.array(fc.dictionary(fc.string(), fc.jsonObject())),
          }),
          async arb => {
            const app = express();
            const handler: ModuleRpcServer.ServiceHandlerFor<
              typeof serverStreamServiceDefinition,
              any
            > = {
              async serverStream(
                request: any[],
                { onReady, onMessage },
                requestContext,
              ) {
                onReady(() => {});
                for (const item of request) {
                  onMessage({
github devexperts / swagger-codegen-ts / src / language / typescript / common / data / __tests__ / serialized-type.spec.ts View on Github external
it('getSerializedPropertyType', () => {
		assert(
			property(string(), serializedTypeArbitrary, boolean(), (name, s, isRequired) => {
				const serialized = getSerializedOptionPropertyType(name, isRequired)(s);
				const safeName = UNSAFE_PROPERTY_PATTERN.test(name) ? `['${name}']` : name;
				const expected = isRequired
					? serializedType(`${safeName}: ${s.type}`, `${safeName}: ${s.io}`, s.dependencies, s.refs)
					: serializedType(
							`${safeName}: Option<${s.type}>`,
							`${safeName}: optionFromNullable(${s.io})`,
							[
								...s.dependencies,
								serializedDependency('Option', 'fp-ts/lib/Option'),
								serializedDependency('optionFromNullable', 'io-ts-types/lib/optionFromNullable'),
							],
							s.refs,
					  );
				expect(serialized).toEqual(expected);
			}),
github rzeigler / waveguide / test / tools.spec.ts View on Github external
export function arbEitherIO(arbe: Arbitrary, arba: Arbitrary<a>): Arbitrary&gt; {
  return fc.boolean()
    .chain((error) =&gt; error ? arbErrorIO(arbe) : arbIO(arba));
}
</a>
github dubzzz / fast-check / example / binary-trees / arbitraries / FullBinaryTreeArbitrary.ts View on Github external
export const fullBinaryTree = (maxDepth: number): fc.Arbitrary&gt; =&gt; {
  const valueArbitrary = fc.integer();
  if (maxDepth &lt;= 0) {
    return fc.record({
      value: valueArbitrary,
      left: fc.constant(null),
      right: fc.constant(null)
    });
  }
  const subTree = fullBinaryTree(maxDepth - 1);
  return fc.boolean().chain(
    (hasChildren: boolean): fc.Arbitrary&gt; =&gt; {
      if (hasChildren) {
        return fc.record({
          value: valueArbitrary,
          left: subTree,
          right: subTree
        });
      }
      return fc.record({
        value: valueArbitrary,
        left: fc.constant(null),
        right: fc.constant(null)
      });
    }
  );
};