title: Using mock sinon to test mysql on node
body: <p>I have a mysql table that I am trying to see if the users get saved or not by testing it using sinon.js mock.</p>
  
  <p>My user.js model has the following code.</p>
  
  <pre><code>saveUser = (userinfo) =&gt; new Promise((resolve,reject)=&gt;{
      var salt = bcrypt.genSaltSync(10);
      var hash = bcrypt.hashSync(userinfo.password, salt);
      userinfo.password = hash;
      userinfo.token = jwt.sign({email : userinfo.email},'secretkeyyo');
      db.query('INSERT INTO user SET ?',userinfo,function(error,results,fields){
          if(error){
              reject('Could not save users to mysql');
          }else{
              resolve(results.insertId);
          }
      })
  });
  </code></pre>
  
  <p>Normally the <code>userinfo</code> has this fields : <code>Owner , firstname lastname email password token</code> which gets saved into the user table after getting hashed</p>
  
  <p>I have a test file that I am trying to run but I am not sure on how to proceed </p>
  
  <pre><code>var expect = require('chai').expect;
  var faker = require('faker');
  const request = require('supertest');
  const should = require('should');
  const sinon = require('sinon');
  const helper = require('../../models/user');
  
  it('should mock insert statement',(done)=&gt;{
      var mock;
      mock = sinon.mock(require('mysql'))
      mock.expects(saveUser).with(queryString, queryParams).yields(null, rows);
  });
  </code></pre>
  
  <p>Not sure on how to use the mocking to test the query. Uncertain about <code>queryString</code> and <code>queryParams</code></p>