How to use the fast-check.string 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 dubzzz / fast-check / example / 005-race / autocomplete / main.spec.tsx View on Github external
// At the end we expect to get results matching 
          if (!suggestions.every(s => s.startsWith(query))) {
            throw new Error(`Must start with ${JSON.stringify(query)}, got: ${JSON.stringify(suggestions)}`);
          }
        })
        .beforeEach(async () => {
          jest.resetAllMocks();
          cleanup();
        })
    ));
});

// Helpers

const AllResultsArbitrary = fc.set(fc.string(), 0, 1000);
const QueriesArbitrary = fc.array(fc.string(), 1, 10);

/**
 * Generate a sequence of events that have to be fired onto the component
 * in order to send it all the queries (characters are fired one by one)
 */
const buildAutocompleteEvents = (input: HTMLElement, queries: string[]) => {
  const autocompleteEvents: Exclude any>[] = [];

  for (const query of queries) {
    for (let numCharacters = 0; numCharacters <= query.length; ++numCharacters) {
      const subQuery = query.substring(0, numCharacters);
      const builder = async () => {
        await act(async () => {
          fireEvent.change(input, { target: { value: subQuery } });
        });
      };
github dubzzz / fuzz-rest-api / test / fuzz.js View on Github external
it('/api/login', async () =>
    await fc.assert(
      fc.asyncProperty(
        fc.record(
          {
            username: fc.string(),
            password: fc.string()
          },
          { withDeletedKeys: true }
        ),
        async payload => {
          await throwIfHttpFailed(httpPost(server, '/api/login', payload));
        }
      ),
      { timeout: 100 }
    ));
  it('/api/profile/:uid', async () =>
github devexperts / swagger-codegen-ts / src / language / typescript / common / data / __tests__ / serialized-type.spec.ts View on Github external
} from '../serialized-type';
import { serializedDependency } from '../serialized-dependency';
import { $refArbitrary } from '../../../../../utils/__tests__/ref.spec';
import { getRelativePath } from '../../../../../utils/ref';
import { pipe } from 'fp-ts/lib/pipeable';
import { arbitrary, nonEmptyArray } from '../../../../../utils/fast-check';
import { none, some } from 'fp-ts/lib/Option';
import { getIOName, getTypeName, UNSAFE_PROPERTY_PATTERN } from '../../utils';
import { when } from '../../../../../utils/string';
import { head } from 'fp-ts/lib/NonEmptyArray';

const serializedDependencyArbitrary = tuple(string(), string()).map(([name, path]) => serializedDependency(name, path));

export const serializedTypeArbitrary = tuple(
	string(),
	string(),
	array(serializedDependencyArbitrary),
	pipe(array($refArbitrary)),
).map(([type, io, dependencies, refs]) => serializedType(type, io, dependencies, refs));

const name = oneof(string(), constant(undefined));

describe('SerializedType', () => {
	it('getSerializedArrayType', () => {
		assert(
			property(serializedTypeArbitrary, name, (s, name) => {
				expect(pipe(s, getSerializedArrayType(name))).toEqual(
					serializedType(
						`Array<${s.type}>`,
						`array(${s.io}${when(name !== undefined, `, '${name}'`)})`,
						[...s.dependencies, serializedDependency('array', 'io-ts')],
						s.refs,
github devexperts / swagger-codegen-ts / src / language / typescript / 3.0 / serializers / __tests__ / schema-object.spec.ts View on Github external
it('should serialize using getSerializedArrayType', () => {
				const schema = record({
					type: constant<'array'>('array'),
					items: record({
						type: constant<'string'>('string'),
						format: constant(none),
						deprecated: constant(none),
					}),
					format: constant(none),
					deprecated: constant(none),
				});
				assert(
					property($refArbitrary, schema, string(), (from, schema, name) => {
						const expected = pipe(
							schema.items,
							serializeSchemaObject(from, name),
							either.map(getSerializedArrayType(name)),
						);
						const serialized = pipe(schema, serializeSchemaObject(from, name));
						expect(serialized).toEqual(expected);
					}),
				);
			});
			it('should support items.$ref', () => {
github gcanti / fp-ts-laws / test / index.ts View on Github external
it('should test Semigroup laws', () => {
    const semigroupSpace: Semigroup = {
      concat: (x, y) => x + ' ' + y
    }
    laws.semigroup(semigroupSpace, eqString, fc.string())
  })
})
github devexperts / swagger-codegen-ts / src / language / typescript / common / data / __tests__ / serialized-type.spec.ts View on Github external
it('getSerializedDictionaryType', () => {
		assert(
			property(serializedTypeArbitrary, string(), (s, name) => {
				expect(getSerializedDictionaryType(name)(s)).toEqual(
					serializedType(
						`{ [key: string]: ${s.type} }`,
						`record(string, ${s.io}${when(name !== undefined, `, '${name}'`)})`,
						[
							...s.dependencies,
							serializedDependency('record', 'io-ts'),
							serializedDependency('string', 'io-ts'),
						],
						s.refs,
					),
				);
			}),
		);
	});
	it('getSerializedUnionType', () => {
github devexperts / swagger-codegen-ts / src / language / typescript / common / data / __tests__ / serialized-type.spec.ts View on Github external
import { arbitrary, nonEmptyArray } from '../../../../../utils/fast-check';
import { none, some } from 'fp-ts/lib/Option';
import { getIOName, getTypeName, UNSAFE_PROPERTY_PATTERN } from '../../utils';
import { when } from '../../../../../utils/string';
import { head } from 'fp-ts/lib/NonEmptyArray';

const serializedDependencyArbitrary = tuple(string(), string()).map(([name, path]) => serializedDependency(name, path));

export const serializedTypeArbitrary = tuple(
	string(),
	string(),
	array(serializedDependencyArbitrary),
	pipe(array($refArbitrary)),
).map(([type, io, dependencies, refs]) => serializedType(type, io, dependencies, refs));

const name = oneof(string(), constant(undefined));

describe('SerializedType', () => {
	it('getSerializedArrayType', () => {
		assert(
			property(serializedTypeArbitrary, name, (s, name) => {
				expect(pipe(s, getSerializedArrayType(name))).toEqual(
					serializedType(
						`Array<${s.type}>`,
						`array(${s.io}${when(name !== undefined, `, '${name}'`)})`,
						[...s.dependencies, serializedDependency('array', 'io-ts')],
						s.refs,
					),
				);
			}),
		);
	});
github gcanti / fp-ts-laws / src / index.ts View on Github external
return liftEq => {
    applicativeM(arb => arb.map(M.of), liftEq)

    const Sc = liftEq(eqBoolean)
    const arbFa = fc.string().map(M.of)
    const afb = (s: string) => M.of(s.length)
    const bfc = (n: number) => M.of(n > 2)
    const associativity = fc.property(arbFa, laws.chain.associativity(M, Sc, afb, bfc))
    const Sb = liftEq(eqNumber)
    const fab = M.of((a: string) => a.length)
    const derivedAp = fc.property(arbFa, laws.chain.derivedAp(M, Sb, fab))

    fc.assert(associativity)
    fc.assert(derivedAp)

    const arb = fc.string().map(M.of)
    const Sa = liftEq(eqString)
    const leftIdentity = fc.property(fc.string(), laws.monad.leftIdentity(M, Sb, afb))
    const rightIdentity = fc.property(arb, laws.monad.rightIdentity(M, Sa))
    const ab = (s: string) => s.length
    const derivedMap = fc.property(arb, laws.monad.derivedMap(M, Sb, ab))

    fc.assert(leftIdentity)
    fc.assert(rightIdentity)
    fc.assert(derivedMap)
  }
}