I'm trying to begin integration/unit testing for my nodejs api but I'm unable to properly connect to my app.js file via supertest.
The below code is written in my main.test.js file
const app = require('../app')
const supertest = require('supertest');
const request = supertest(app)
it('posts color', async () => {
await request.post('/postColor')
.send({
"Color": "Green",
}).expect(201)
})
Below is my app.js file
import express from 'express';
const app = express();
export default app;
I broke apart my index.js file into an app.js and index.js file.
My index.js imports app from app.js and sets it up to listen to whichever port I need it to. My main.test.js file imports app from app.js and uses it as shown above in accordance with supertest.
I keep getting the following error
TypeError: app.address is not a function
4 |
5 | it('posts color', async () => {
> 6 | await request.post('/postColor')
| ^