title: How to mock a function while testing Node.js endpoint using chai-http
body: <p><strong>Endpoint code:</strong>
  <div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>app.post('/api/v1/user', async function (req, res) {
      const user = await createUser(req);
      res.send(user);
  });</code></pre>
  </div>
  </div>
  </p>
  <p><strong>Integration test:</strong>
  Below test is written to test the endpoint (<code>/api/v1/user</code>). <code>createUser(req);</code> function creates the user into DB. I want to skip creation of user into DB while testing.
  Could you help me to mock <code>createUser(req);</code> in the below test.</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>import chai from 'chai';
  import chaiHttp from 'chai-http';
  chai.use(chaiHttp);
  import { app } from '../../server';
  
  describe('Create user tests', function () {
      it('user should be created', function (done) {
          chai.request(app)
              .post('/api/v1/user')
              .set({
                  'content-type': 'application/json',
              })
              .send({
                  name: 'xxxxx',
                  email: 'xxx@mail.com',
              })
              .end((err, res) =&gt; {
                  res.should.have.status(200);
  
                  done();
              });
      });
  });</code></pre>
  </div>
  </div>
  </p>