fastify / fastify/fastify-express

When testing express application with inject, payload is always empty

Open
#54 4 comments 3 reactions 0 assignees View on GitHub
bug
Dominant language
JavaScript
Stars
272
Forks
28
Avg merge
1m
Merged PRs (30d)
1

Description

### Prerequisites

- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported

### Fastify version

3.22.1

### Plugin version

0.3.3

### Node.js version

16.4.0

### Operating system

macOS

### Operating system version (i.e. 20.04, 11.3, 10)

11.2.1

### Description

I'm having an express application which will transition completely to Fastify in the future. We want to write integration tests for this application and leverage fastify.inject but when executing a request, the payload is always empty.

To run our tests we are using Jest (27.2.5).

### Steps to Reproduce

```
// server.ts

const router = express.Router();

const app = fastify();

router.get('/test', (req, res) => {
res.status(201);
res.json({ hello: 'world' });
});

await app.register(fastifyExpress).after(async () => {
app.use(router);
});
```

```
// test.ts

test('No query parameters', async () => {
app.inject().get('/test').end((err, response) => {
expect(response.statusCode).toEqual(201);
expect(response.json()).toEqual({ hello: 'world' });
});
});
```

### Expected Behavior

I would expect a body and not an empty string.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.