How to use the fast-check.configureGlobal 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 dubzzz / fast-check / example / 005-race / userProfile / main.spec.tsx View on Github external
import fc from 'fast-check';
import * as React from 'react';

import UserProfilePage from './src/UserProfilePage';

import { render, cleanup, act } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';

// If you want to test the behaviour of fast-check in case of a bug:
const bugId = undefined; // = 1; // to enable bug

if (!fc.readConfigureGlobal()) {
  // Global config of Jest has been ignored, we will have a timeout after 5000ms
  // (CodeSandbox falls in this category)
  fc.configureGlobal({ interruptAfterTimeLimit: 4000 });
}

describe('UserProfilePage', () => {
  it('should not display data related to another user', () =>
    fc.assert(
      fc
        .asyncProperty(fc.uuid(), fc.uuid(), fc.scheduler({ act }), async (uid1, uid2, s) => {
          // Arrange
          const getUserProfileImplem = s.scheduleFunction(function getUserProfile(userId: string) {
            return Promise.resolve({ id: userId, name: userId });
          });

          // Act
          const { rerender, queryByText, queryByTestId } = render(
            <UserProfilePage userId={uid1} getUserProfile={getUserProfileImplem} bug={bugId} />
          );
github dubzzz / fast-check / example / 005-race / autocomplete / main.spec.tsx View on Github external
import '@testing-library/jest-dom/extend-expect';

import { search } from './src/Api';

// If you want to test the behaviour of fast-check in case of a bug:
const bugs = {
  //  enableBugBetterResults: true,
  //  enableBugUnfilteredResults: true,
  //  enableBugUnrelatedResults: true,
  //  enableBugDoNotDiscardOldQueries: true
};

if (!fc.readConfigureGlobal()) {
  // Global config of Jest has been ignored, we will have a timeout after 5000ms
  // (CodeSandbox falls in this category)
  fc.configureGlobal({ interruptAfterTimeLimit: 4000 });
}

describe('AutocompleteField', () => {
  it('should suggest results matching the value of the autocomplete field', () =>
    fc.assert(
      fc
        .asyncProperty(AllResultsArbitrary, QueriesArbitrary, fc.scheduler({ act }), async (allResults, queries, s) => {
          // Arrange
          const searchImplem: typeof search = s.scheduleFunction(function search(query, maxResults) {
            return Promise.resolve(allResults.filter(r => r.includes(query)).slice(0, maxResults));
          });

          // Act
          const { getByRole, queryAllByRole } = render(<AutocompleteField search={searchImplem} {...bugs} />);
          const input = getByRole('input') as HTMLElement;
          s.scheduleSequence(buildAutocompleteEvents(input, queries));
github dubzzz / fast-check / example / 005-race / dependencyTree / main.spec.ts View on Github external
import fc from 'fast-check';

import { dependencyTree, PackageDefinition } from './src/dependencyTree';

if (!fc.readConfigureGlobal()) {
  // Global config of Jest has been ignored, we will have a timeout after 5000ms
  // (CodeSandbox falls in this category)
  fc.configureGlobal({ interruptAfterTimeLimit: 4000 });
}

describe('dependencyTree', () => {
  it('should be able to compute a dependency tree for any package of the registry', () =>
    fc.assert(
      fc.asyncProperty(AllPackagesArbitrary, fc.scheduler(), async (packages, s) => {
        // Arrange
        const selectedPackage = Object.keys(packages)[0];
        const fetch: (name: string) => Promise<PackageDefinition> = s.scheduleFunction(function fetch(packageName) {
          return Promise.resolve(packages[packageName]);
        });

        // Act
        dependencyTree(selectedPackage, fetch); // without bugs
        // dependencyTree(selectedPackage, fetch, true); // or with bugs