playwright-test-commons - v0.8.0
    Preparing search index...

    Function pollUntil

    • Calls an API repeatedly until its body meets a condition. Non-2xx responses count as "not yet" and are retried. Fails the test if the condition isn't met within the timeout.

      Type Parameters

      • T

        the body's type, taken from the client method

      Parameters

      • apiCall: () => Promise<APIResponse<T>>

        makes the request, e.g. () => Posts.getPost(id)

      • condition: (body: T) => boolean

        returns true once the body is as expected

      • options: PollOptions = {}

      Returns Promise<T>

      the body that met the condition

      // Posts.getPost is declared as this.get<Post>(...), so body is a Post
      const post = await pollUntil(
      () => Posts.getPost(id),
      (body) => body.status === "published",
      { message: "post to be published" }
      );