forwardemail / forwardemail/supertest
How to get an access to request object before request ?
- Dominant language
- JavaScript
- Stars
- 14.4k
- Forks
- 782
- PR merge metrics
- No merged PRs in 30d
Description
Without supertest:
```
it('success', () => {
const req = {
user: {
name: 'Jack',
type: 'admin'
}
};
const next = jest.fn();
authenticateAdmin(req, {}, next);
expect(next).toBeCalled();
});
```
With jest
```
beforeEach(() => {
const app = express();
app.post(
'/',
authenticateAdmin,
() => {}
);
});
it('success', () => {
request(app)
.post('/')
.send({
user: {
name: 'Jack',
type: 'admin'
}
})
});
```
But with `send`, I send body object. How to set an object property of `request` ?
I want to test it:
```
module.exports = (req, res, next) => {
const user = req.user;
console.log({ req });
if (user.type !== 'admin') {
return res.status(403).json({ error: req.t('errors.auth.access_error') });
}
next();
};
```
Contributor guide
Assessment
This issue has not been assessed yet.