title: Custom matcher in jest
body: <p>I'm trying to create a custom matcher in Jest similar to stringMatching but that accepts null values. However, the docs don't show how to reuse an existing matcher. So far, I've got something like this:</p>
  
  <pre><code>expect.extend({
      stringMatchingOrNull(received, argument) {
          if (received === null) {
              return {
                  pass: true,
                  message: () =&gt; 'String expected to be null.'
              };
          }
  
          expect(received).stringMatching(argument);
      }
  });
  </code></pre>
  
  <p>I'm not sure this is the correct way to do it because I'm not returning anything when I call the stringMatching matcher (this was suggested <a href="https://github.com/facebook/jest/issues/2547#issuecomment-271573287" rel="noreferrer">here</a>). When I try to use this matcher, I get: <code>expect.stringMatchingOrNull is not a function</code>, even if this is declared in the same test case:</p>
  
  <pre><code>expect(player).toMatchObject({
      playerName: expect.any(String),
      rank: expect.stringMatchingOrNull(/^[AD]$/i)
      [...]
  });
  </code></pre>
  
  <p>Please, can somebody help me showing the correct way to do it?</p>
  
  <p>I'm running the tests with Jest 20.0.4 and Node.js 7.8.0.</p>