forwardemail / forwardemail/supertest

Supertest is casting a number to string?

Open
#755 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
14.4k
Forks
782
PR merge metrics
No merged PRs in 30d

Description

I have an endpoint that takes a payload with just one property. That property has a validation rule to be a string and returns a 400 Bad request otherwise. Here is the validation class
```typescript
import { IsString } from "class-validator";

export class CreateQuestionDto {

@IsString()
readonly text: string;
}
```
In postman, when I hit the endpoint with a payload `{ "text": 1}` I get back
```json
{
"statusCode": 400,
"message": [
"text must be a string"
],
"error": "Bad Request"
}
```
I have tried two ways to make the test failed
```typescript
it.only('Bad request [400]', () => {
return request(app.getHttpServer())
.post('/questions')
.send({ text: 1})
.expect(201)
})
// and also
it.only('Bad request [400]', () => {
return request(app.getHttpServer())
.post('/questions')
.send({ text: parseInt('1', 10)})
.expect(201)
})
```
Both times I get in the console
```shell
Create [POST /questions]
✓ Bad request [400] (57 ms)
```
When the test should be failing. In the case of `parseInt('1', 10)` Shouldn't be evident for supertest that the value is a number?

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.