Top-level 'await' does not work #692
Answered
by
KeisukeNagakawa
KeisukeNagakawa
asked this question in
Q&A
-
Hi, first of all, thank you for your great repository. I have a question on running this code. When I run this code below, following error occurs and I can not fix it. import { expect } from "@jest/globals"
// ESM
import { testApiHandler } from "next-test-api-route-handler"
// Import the handler under test from the pages/api directory
import type { PageConfig } from "next"
import endpoint from "pages/api/interests/list"
// import endpoint from "../pages/api/interests/list"
// Respect the Next.js config object if it's exported
const handler: typeof endpoint & { config?: PageConfig } = endpoint
testApiHandler({
handler,
requestPatcher: (req) => (req.headers = { key: process.env.SPECIAL_TOKEN }),
test: async ({ fetch }) => {
const res = await fetch({ method: "POST", body: "data" })
await expect(res.json()).resolves.toStrictEqual({ hello: "world" }) // ◄ Passes!
},
}) error:
I have tried few days with this problem and I could not fix it. Could someone help me solve this? My tsconfig.json and jest.config and package.json are as follows: tsconfig.json
jest.config
package.json
|
Beta Was this translation helpful? Give feedback.
Answered by
KeisukeNagakawa
Oct 14, 2022
Replies: 1 comment
-
Sorry guys, I fixed it by myself by surrounding
|
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
KeisukeNagakawa
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sorry guys, I fixed it by myself by surrounding
it
function.