title: How to test Validation pipe is throwing the expect error for improperly shaped request on NestJS
body: <p>I'm using NestJS 7.0.2 and have globally enabled validation pipes via <code>app.useGlobalPipes(new ValidationPipe());</code>.  </p>
  
  <p>I'd like to be able to have a unit test that verifies that errors are being thrown if the improperly shaped object is provided, however the test as written still passes. I've seen that one solution is to do this testing in e2e <a href="https://stackoverflow.com/questions/58843038/how-to-manually-test-input-validation-with-nestjs-and-class-validator">via this post</a>, but I'm wondering if there is anything I'm missing that would allow me to do this in unit testing.</p>
  
  <p>I have a very simple controller with a very simple DTO.</p>
  
  <p>Controller</p>
  
  <pre><code>async myApi(@Body() myInput: myDto): Promise&lt;myDto | any&gt; {
    return {};
  }
  </code></pre>
  
  <p>DTO</p>
  
  <pre><code>export class myDto {
    @IsNotEmpty()
    a: string;
  
    @IsNotEmpty()
    b: string | Array&lt;string&gt;
  }
  </code></pre>
  
  <p>Spec file</p>
  
  <pre><code>  describe('generate', () =&gt; {
      it('should require the proper type', async () =&gt; {
        const result = await controller.generate(&lt;myDto&gt;{});
        // TODO: I expect a validation error to occur here so I can test against it.
        expect(result).toEqual({})
      })
    })
  </code></pre>
  
  <p>It also fails if I do not coerce the type of <code>myDto</code> and just do a <code>ts-ignore</code> on a generic object. </p>