You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When running jest + supertest simple API end point test we get the following error.
"TypeError: res.status is not a function" when running
Actual behavior
npmruntest>mtrade@0.1.0dev>nextdevready-startedserveron0.0.0.0:3000,url: http://localhost:3000info-Loadedenvfrom/home/ken/Programming/next-mtrade/.envevent-compiledclientandserversuccessfullyin456ms(264modules)^Cken@kmb:~/Programming/next-mtrade$npmruntest>mtrade@0.1.0test>jestFAIL__tests__/api/hello.spec.ts(11.442s)APIRoute-/api/hello✕respondswith"Hello, World"(10002ms)●APIRoute-/api/hello›respondswith"Hello, World"
TypeError: res.statusisnotafunction9|res: NextApiResponse<ResponseData>10|){>11|res.status(200).json({message: "Hello from Next.js!"});|^12|}13|atServer.<anonymous>(src/pages/api/hello.ts:11:9)atstep(src/pages/api/hello.ts:33:23)atObject.next(src/pages/api/hello.ts:14:53)atsrc/pages/api/hello.ts:8:71atObject.<anonymous>.__awaiter(src/pages/api/hello.ts:4:12)atServer.hello(src/pages/api/hello.ts:40:12)●APIRoute-/api/hello›respondswith"Hello, World"
thrown: "Exceeded timeout of 10000 ms for a test. Add a timeout value to this test to increase the timeout, if this is a long-running test. See https://jestjs.io/docs/api#testname-fn-timeout."4|5|describe("API Route - /api/hello",()=>{>6|it('responds with "Hello, World"',async()=>{|^7|constresponse=awaitrequest(hello).get("/api/hello");8|9|expect(response.status).toBe(200);at__tests__/api/hello.spec.ts:6:5atObject.<anonymous>(__tests__/api/hello.spec.ts:5:1)
Test Suites: 1failed,1total
Tests: 1failed,1total
Snapshots: 0total
Time: 11.483s,estimated13sRanalltestsuites.Jestdidnotexitonesecondafterthetestrunhascompleted.'This usually means that there are asynchronous operations that weren'tstoppedinyourtests.ConsiderrunningJestwith`--detectOpenHandles`totroubleshootthisissue.
Expected behavior
Jest + Supertest API end point test should pass
We except a status code of 200 and a json message containgin "{"message":"Hello from Next.js!"}"
Code to reproduce
// __tests__/api/hello.spec.tsimportrequestfrom"supertest";importhellofrom"../../src/pages/api/hello";describe("API Route - /api/hello",()=>{it('responds with "Hello, World"',async()=>{constresponse=awaitrequest(hello).get("/api/hello");expect(response.status).toBe(200);expect(response.body).toEqual({message: "Hello, World"});},10000);// Set a 10-second timeout});
//src/pages/api/hello.tsimporttype{NextApiRequest,NextApiResponse}from"next";typeResponseData={message: string;};exportdefaultasyncfunctionhello(req: NextApiRequest,res: NextApiResponse<ResponseData>){res.status(200).json({message: "Hello from Next.js!"});}
Describe the bug
Node.js version: v20.9.0
OS version: Ubuntu 22.04.3 LTS
Description:
Next.js v"13.4.0"
When running jest + supertest simple API end point test we get the following error.
"TypeError: res.status is not a function" when running
Actual behavior
Expected behavior
Jest + Supertest API end point test should pass
We except a status code of 200 and a json message containgin "{"message":"Hello from Next.js!"}"
Code to reproduce
My repo
https://github.com/kbventures/next-mtrade
Checklist
Similiar issue for express.js
The text was updated successfully, but these errors were encountered: