How to use the fast-check.asyncProperty 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 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 dubzzz / fast-check / example / 005-race / autocomplete / main.spec.tsx View on Github external
it('should display more and more sugestions as results come', () =>
    fc.assert(
      fc
        .asyncProperty(AllResultsArbitrary, QueriesArbitrary, fc.scheduler({ act }), async (allResults, queries, s) => {
          // Arrange
          const query = queries[queries.length - 1];
          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;
          for (const event of buildAutocompleteEvents(input, queries)) {
            await event.builder();
          } // All the user's inputs have been fired onto the AutocompleField

          // Assert
          let suggestions: string[] = [];
github rzeigler / waveguide / test / wave.spec.ts View on Github external
it("- composition", () =>
        fc.assert(
          fc.asyncProperty(
            arbIO(fc.string()),
            fc.constant(strlen),
            fc.constant(even),
            functor.composition
          )
        )
      );
github rzeigler / waveguide / test / wave.spec.ts View on Github external
it("any number of successful IOs surrounding a failed IO produces the error of the failed IO", () =>
      fc.assert(
        fc.asyncProperty(
          fc.array(arbIO<string, number>(fc.integer())),
          arbErrorIO<string, number>(fc.constant("failure")),
          fc.array(arbIO<string, number>(fc.integer())),
          (before, err, after) => {
            const arr = [...before, err, ...after]
            const result = array.sequence(io.instances)(arr)
            return eqvIO(result, io.as(err, [] as number[]));
          }
        )
      )
    );
github rzeigler / waveguide / test / fiber.spec.ts View on Github external
it("uninterruptible fibers are not interruptible", () =>
      fc.assert(
        fc.asyncProperty(
          fc.nat(50),
          (delay) =>
            expectExit(
              io.chain(
                makeDeferred<never, void>(),
                (latch) =>
                  io.chain(makeRef(false),
                    (cell) =>
                      io.chain(
                        io.fork(
                          io.uninterruptible(io.applySecond(latch.wait, cell.set(true)))
                        ),
                        (child) =>
                          io.applySecond(
                            io.fork(io.shiftAsyncBefore(child.interrupt)),
                            io.applySecond(
github rzeigler / waveguide / test / deferred.spec.ts View on Github external
it("allows for multiple fibers to coordinate", () =>
      fc.assert(
        fc.asyncProperty(
          fc.nat(50),
          (delay) =>
            expectExit(
              io.chain(makeDeferred<never, number>(),
                (def) =>
                  io.applySecond(
                    io.fork(io.delay(def.done(42), delay)),
                    def.wait
                  )
              ),
              done(42)
            )
        )
      )
    );
github dubzzz / fuzz-rest-api / test / fuzz.js View on Github external
it('/api/comment', async () =>
    await fc.assert(
      fc.asyncProperty(
        inferPayloadArbitrary(
          {
            user: { login: 'toto' },
            comment: { message: 'lorem ipsum', postId: 5, commentId: 8, public: false, details: ['', 5] }
          },
          true,
          true
        ),
        async payload => {
          await throwIfHttpFailed(httpPost(server, '/api/comment', payload));
        }
      ),
      { timeout: 100 }
    ));
});
github rzeigler / waveguide / test / wave.spec.ts View on Github external
it("- homomorphism", () =>
        fc.assert(
          fc.asyncProperty(
            fc.constant(strlen),
            fc.string(),
            applicative.homomorphism
          )
        )
      );
github rzeigler / waveguide / test / wave.spec.ts View on Github external
it("- interchange", () =>
        fc.assert(
          fc.asyncProperty(
            fc.string(),
            arbIO(fc.constant(strlen)),
            applicative.interchange
          )
        )
      );
github rzeigler / waveguide / test / wave.spec.ts View on Github external
it(" - derived map", () =>
        fc.assert(
          fc.asyncProperty(
            fc.constant(strlen),
            arbIO(fc.string()),
            monad.derivedMap
          )
        )
      );