jbrumwell / mock-knex

A mock knex adapter for simulating a database during testing
MIT License
239 stars 71 forks source link

issues with error propagating #82

Closed jmarucha closed 5 years ago

jmarucha commented 6 years ago

I'm writing unit tests to handle possible DB errors:

tracker.on('query', (query) => {
    expect(query.method).to.equal('del');
    query.reject(Error('No Rows Deleted'));
});

Later in code when I print error.message of the error propagating it is

   delete from "resource_type" where "id" = $1 - No Rows Deleted

which is query.sql + ' - ' + error.message of what I would expect. This makes it impossible to test any error handling.

Using mock-knex 0.4.2, knex 0.14.4 and bookshelf 0.13.3

jbrumwell commented 5 years ago

@jmarucha what is printed?

jbrumwell commented 5 years ago

This is from the tests, it should reject the promise with the error you throw

it('query#reject', (done) => {
      tracker.on('query', (query) => {
        query.reject('i threw up');
      });

      db.select('field').from('test-table').catch((error) => {
        expect(error.message).to.be.a('string');
        expect(error.message.indexOf('i threw up')).to.not.equal(-1);
        done();
      });
    });