forwardemail / forwardemail/supertest
TypeError: Cannot read property 'address' of undefined
- Dominant language
- JavaScript
- Stars
- 14.4k
- Forks
- 782
- PR merge metrics
- No merged PRs in 30d
Description
I created an express.js server with ts and tried to test it, but got an error.
I can't find a solution no matter how I search.
**server.ts**
```
import App from './app';
import PostsRouter from './routes/posts';
export const app = new App(
[
new PostsRouter(),
],
3000,
).listen();
```
**app.ts**
```
import * as express from 'express';
class App {
public app: express.Application;
public port: number;
constructor(controllers: any[], port: number) {
this.app = express();
this.port = port;
this.initializeControllers(controllers);
}
private initializeControllers(controllers: any[]) {
controllers.forEach((controller) => {
this.app.use('/', controller.router);
});
}
public listen() {
this.app.listen(this.port, () => {
console.log(`App listening on the port ${this.port}`);
});
}
}
export default App;
```
**posts.spec.ts**
```
import * as request from "supertest";
import { app } from "../server";
describe("GET /posts", () => {
it("respond with json", async done => {
await request(app)
.get("/posts")
.set("Accept", "application/json")
.expect("Content-Type", /json/)
.expect(200, done);
});
});
```

Contributor guide
Assessment
This issue has not been assessed yet.