title: How to test a async function in Nest js with jest
body: <p>im doing a simple test with my new framework Nest js, but the first time I run the command npm run test im getting this error</p>
  <pre><code>●  Cannot log after tests are done. Did you forget to wait for something async in your test?
      Attempted to log &quot;SUCCESS conection to MEMCACHED server&quot;.
  
        21 |   // this function Stores a new value in Memcached.
        22 |   setKey(key : string, value : string , timeExp:number) : Promise&lt;boolean&gt;{
      &gt; 23 |     // Transform the callback into a promise to be used in the controller
           |                 ^
        24 |     return new Promise((resolve,reject) =&gt;{
        25 |       // Using memcached api to set a key
        26 |       memcached.set(key, value, timeExp, async function (err) {
  
        at BufferedConsole.log (../node_modules/@jest/console/build/BufferedConsole.js:201:10)
        at modules/cache/application/cache.service.ts:23:17
        at allocate (../node_modules/jackpot/index.js:125:5)
        at Socket.either (../node_modules/jackpot/index.js:166:5)
  </code></pre>
  <p>but this is my test file</p>
  <pre><code>describe('Cache Controller', () =&gt; {
    let controller: CacheController;
  
    beforeEach(async () =&gt; {
      const module: TestingModule = await Test.createTestingModule({
        controllers: [CacheController],
      }).compile();
  
      controller = module.get&lt;CacheController&gt;(CacheController);
    });
  
    it('should be defined', () =&gt; {
      expect(controller).toBeDefined();
    });
  });
  
  </code></pre>
  <ul>
  <li>This is the function that are getting the error (don't know why if im not testing this function)</li>
  </ul>
  <pre><code>// this function Stores a new value in Memcached.
    async setKey(key : string, value : string , timeExp:number) : Promise&lt;boolean&gt;{
      // Transform the callback into a promise to be used in the controller
      return await new Promise((resolve,reject) =&gt;{
        // Using memcached api to set a key
        memcached.set(key, value, timeExp, function (err) {
          if (err) return reject(err);
          resolve(true)
        });  
      });
    }
  </code></pre>