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.

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

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();
          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(fc.integer())),
          arbErrorIO(fc.constant("failure")),
          fc.array(arbIO(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(),
                (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(),
                (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
          )
        )
      );