title: Sinon - spy not being called but test enters into the function
body: <p>I made the test for the function with two stubs, actually stubs are working, and if I console.log res.json or next in any part of the function it shows the spy objects inside. Anyway the spy is not being called, when I make the assertion it says "expected spy to have been called at least once but was never called". The program works, but the test is crazy. Help me please!</p>
  
  <p>I have function like this:</p>
  
  <pre><code>export function createOrUpdateToken(req, res, next) {
    const { code, redirect_uri, realm_id, quickbooksAuth } = req.body;
  
    if (!code || !redirect_uri || !realm_id) {
      const message = 'Authorization code, Redirect URI and Realm Id are required';
      return next(new CustomError('Bad Request', message, 400));
    }
    return issueRefreshTokenBasedOnAuthorizationCode(
      {
        redirect_uri,
        authorizationCode: code,
        authorization: quickbooksAuth,
      })
      .then((response) =&gt; {
        const { body: { refresh_token } } = response;
        return securityModel.findOneAndUpdate(
          { realmId: realm_id },
          { refreshToken: refresh_token },
          { upsert: true },
          (err) =&gt; {
            if (err) return next(err);
            return res.json('Authentication successfull');
          });
      })
      .catch((err) =&gt; {
        return next(err);
      });
  }
  </code></pre>
  
  <p>And the test is like this: </p>
  
  <pre><code>it('Should create or update token', () =&gt; {
    req.body = {
      code: '1234',
      redirect_uri: 'www.test.com',
      realm_id: '12345',
      quickbooksAuth: 'dhajksdas.dsajdosaiudjsa.dsaojpdas'
    };
    sinon
      .stub(intuit, 'issueRefreshTokenBasedOnAuthorizationCode')
      .resolves({
        body: {
          refresh_token: 'hjdklasdashda.dsa.dasdsa.dasddasdas'
        }
      });
  
    sinon
      .stub(securityModel, 'findOneAndUpdate')
      .withArgs({ realmId: req.body.realm_id },
        { refreshToken: 'hjdklasdashda.dsa.dasdsa.dasddasdas' })
      .yields(null);
    createOrUpdateToken(req, res, next);
    sinon.assert.called(res.json);
  });
  </code></pre>
  
  <p>The conditions are:</p>
  
  <pre><code>beforeEach(() =&gt; {
        res = {
          json: sinon.spy()
        };
        next = sinon.spy();
      });
  
      afterEach(() =&gt; {
        sinon.restore();
      })
  </code></pre>