title: Jest : Testing for type or null
body: <p>I have a test where i want to test if my received object value types match a schema. Prob is that for some keys i may receive something or null</p>
  
  <p>I tried this so far </p>
  
  <pre><code>  const attendeeSchema = {
    birthDate: expect.extend(toBeTypeOrNull("Date")),
    contact: expect.extend(toBeTypeOrNull(String)),
    createdAt: expect.any(Date),
    firstName: expect.any(String),
    id: expect.any(Number),
    idDevice: expect.extend(toBeTypeOrNull(Number)),
    information: expect.extend(toBeTypeOrNull(String)),
    lastName: expect.any(String),
    macAddress: expect.extend(toBeTypeOrNull(String)),
    updatedAt: expect.any(Date),
    // state: toBeTypeOrNull()
  };
  
      const toBeTypeOrNull = (received, argument) =&gt; {
    const pass = expect(received).toEqual(expect.any(argument));
    if (pass || received === null) {
      return {
        message: () =&gt; `Ok`,
        pass: true
      };
    } else {
      return {
        message: () =&gt; `expected ${received} to be ${argument} type or null`,
        pass: false
      };
    }
  };
  </code></pre>
  
  <p>and on my test</p>
  
  <pre><code> expect(res.result.data).toBe(attendeeSchema);
  </code></pre>
  
  <p>i also tried tobeEqual and other stuff....</p>
  
  <p>my test doenst pass with </p>
  
  <pre><code>TypeError: any() expects to be passed a constructor function. Please pass one or use anything() to match any object.
  </code></pre>
  
  <p>I have no idea what to do here..
  If someone has an idea
  Thanks</p>