AndyA
Convex Community6mo ago
10 replies
Andy

withSearchIndex does not return results when running tests, but does in production.

Assume you have the following query:

await db.query("tasks").withSearchIndex("search_name", (q) => q.search("name", taskName)).paginate(paginationOpts)


When running the code from the frontend, it functions as expected, returning results for exact and partial string matches; however, it returns no results when attempting to execute with convex-test via the following test:

    test("returns a task", async () => {
      const response = await asUser.query(api.tasks.listTasks, {
        paginationOpts: { numItems: 10, cursor: null },
        name: "Foo"
      })
      expect(response).toMatchObject({
        continueCursor: "_end_cursor",
        isDone: true,
        page: [] // Search doesn't return tasks, just an empty array.
      })
    })


Replacing the withSearchIndex method with withIndex returns results.
Was this page helpful?