So, using supertest and jest, when testing my simple controller I get a timeout message. I'm not sure if I am missing something from the config for jest set-up?
app.ts
import express from 'express'
import bodyParser from 'body-parser'
import cors from 'cors'
import { UserRoute } from './components/user'
const App = () => {
const app = express()
app.use(bodyParser.json({ limit: "50mb" }))
app.use(bodyParser.urlencoded({ limit: "50mb", extended: true }))
app.use(cors())
app.use('/api/auth', UserRoute)
return app
}
export default App
user.controller.ts
export const SignUp = async (req: Request, res: Response, next: NextFunction) => {
res.json({ message: "pass!" });
}
user.route.ts
import { Router } from 'express'
import { SignUp } from './user.controller'
const router = Router()
router
.route('/signup')
.get(SignUp)
export default router
user.controller.spec.ts
import App from '../../../app'
import supertest from 'supertest'
const request = supertest(App);
describe('Testing user controller', () => {
it('testing /signup', async () => {
const res = await request.get("/signup");
expect(res.body.message).toBe("pass!");
})
})
My jest timeout is 10000, not sure what is missing here for my controller not to return? Potentially to do with async/await?