title: unt test for jest custom validation class (class-validator) and its message?
body: <p>I am working on a nodeJs project, using typescript.
  Here I am using class-validator to validate inputs and uses jest to run unit test.</p>
  
  <p>However, I'm not sure how I could test customized error message.
  I saw a lots of to use functions but almost none for class.</p>
  
  <p>Here's the error message</p>
  
  <pre><code>Matcher error: received value must be a function
  
  Received has type:  string
  Received has value: "1"
  </code></pre>
  
  <p>Here's my code</p>
  
  <p>unit_test.ts</p>
  
  <pre><code><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>  describe("GET: search/api", () =&gt; {
        class MyClass {
         @IsDefined()
         @Validate(DateConditionCheck, {
        message: 'Please check your date input!'
      })
         dd: number;
      };
  
      const model: any = new MyClass ();
  
      model.dd = 1;
  
      it('should throw an error message when date input is incorrect', async () =&gt; {
        return validate(model).then(errors =&gt; {
           expect(errors.length).toBe(1);
           expect(model.dd).toThrow('Date condition seems wrong!');
       });
     });
   });</code></pre>
  </div>
  </div>
  
  </code></pre>
  
  <p>dateconditioncheck.ts</p>
  
  <pre><code><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>    import {
        IsDefined,
        IsBoolean,
        IsString,
        IsEmail,
        IsNumberString,
        IsAlphanumeric,
        IsNotEmpty,
        MaxLength,
        MinLength,
        IsNumber,
        IsEnum,
        IsOptional,
        Max,
        Min,
        Length,
        Matches,
        Validate,
        ValidatorConstraint,
        ValidatorConstraintInterface,
        ValidationArguments,
        registerDecorator,
        ValidationOptions
      } from 'class-validator'
      import * as moment from 'moment'
  
      /**
       * Custom validator
       *
       */
      @ValidatorConstraint({ name: 'dateConditionCheck', async: false })
      export class DateConditionCheck implements ValidatorConstraintInterface {
        validate(text: any, args: ValidationArguments) {
          const jsondata = JSON.parse(JSON.stringify(args.object))
          if (args.property === 'dd') {
            return moment(Number(jsondata.yyyy) + '-' + Number(jsondata.mm) + '-' + Number(jsondata.dd), 'YYYYMMDD').isValid()
          }
  
          if (args.property === 'dd2') {
            return moment(
              Number(jsondata.yyyy2) + '-' + Number(jsondata.mm2) + '-' + Number(jsondata.dd2),
              'YYYYMMDD'
            ).isValid()
          }
          return true
        }
  
        defaultMessage(args: ValidationArguments) {
          return 'Please check your date input!'
        }
      }</code></pre>
  </div>
  </div>
  
  </code></pre>
  
  <p>Please let me know if you need any extra infos.
  Appreciate all your helps!</p>