0

I am using mariasql 0.2.6 in my code.

Following is the sample code:

var Client = require('mariasql');

var c = new Client();
  c.connect({
  host: '127.0.0.1',
  user: 'foo',
  password: 'bar',
  db: 'mydb'
});

function getData() {
  c.query('SELECT * FROM users where id = 2', (err, rows) => {
    if (err) {
      return error;
    } else {
      return rows;
    } 
  });
}

Now I'm writing unit test cases for this method and i am not sure how to stub the db call.

  • 1
    This is a quite simple thing to do. Either you use dependency injection to override the mysql library used, or you use a link seam to swap the library being imported. See this answer: https://stackoverflow.com/questions/44294170/mocking-redis-constructor-with-sinon/44489058#44489058 (upvote if useful) – oligofren Jun 21 '17 at 17:33
  • I used sinon to stub connect method: it('stub db call', sinon.test(function (done) { this.stub(connect, 'query', (query, cb) => { cb('db operation failed', null); } }); – Shailesh Devadiga Jun 23 '17 at 09:52

0 Answers0