title: Writing unit tests for method that uses jwt token in javascript
body: <p>I have been trying to write unit test in javascript for the method which uses jwt token validation. So the results are fetched only if the token is valid.</p>
  
  <p>I want to mock the jwt token and return results. Is there any way to do it ? I tried using ava test framework, mock require, sinon but I am unable to do it. </p>
  
  <p>Any thoughts ?</p>
  
  <p>Code:</p>
  
  <pre><code>I am trying to mock jwt.verify    
  
  **unit test:**
  
  const promiseFn = Promise.resolve({ success: 'Token is valid' });
  
  mock('jsonwebtoken', {
          verify: function () {         
              return promiseFn;   
          }
  });
  
  const jwt = require('jsonwebtoken');
  
  const data =  jwt.verify(testToken,'testSecret');
  
  console.log(data)
  
  
  **Error :**
  
  ERROR
      {"name":"JsonWebTokenError","message":"invalid token"} 
  
  
  So the issue here is that, its actually verifying the token but not invoking the mock.
  </code></pre>