elysiajs / elysia

Ergonomic Framework for Humans
https://elysiajs.com
MIT License
10.15k stars 217 forks source link

`t.String()` validation does not work on body. #607

Closed touhidurrr closed 5 months ago

touhidurrr commented 5 months ago

What version of Elysia.JS is running?

1.0.13

What platform is your computer?

Microsoft Windows NT 10.0.22631.0 x64

What steps can reproduce the bug?

use this test:

import { describe, expect, test } from 'bun:test';
import { Elysia, t } from 'elysia';

describe('string schema', async () => {
  const app = new Elysia().patch('/test', async ({ body }) => body, { body: t.String() });

  const res = await app.handle(
    new Request(`http://localhost/test`, {
      method: 'PATCH',
      body: 'hello',
    })
  );

  test('t.String() works', async () => {
    const body = await res.text();
    expect(res.status).toBe(200);
    expect(body).toBeString();
    expect(body).toBe('hello');
  });
});

What is the expected behavior?

It works

What do you see instead?

It does not work

Additional information

I wasted hours of my time only to realize this was a bug.