knex/test/unit/interface.js

39 lines
1.1 KiB
JavaScript
Raw Normal View History

2018-04-25 23:11:24 +02:00
'use strict';
2019-07-10 22:48:43 +01:00
const _interface = require('../../lib/interface');
const chai = require('chai');
2018-04-25 23:11:24 +02:00
describe('interface', function() {
it('catch and rethrow with an async stack trace', function(done) {
const error = new Error('Some SQL error');
2018-04-25 23:11:24 +02:00
function SomeClass() {
this.client = {
config: {
asyncStackTraces: true,
2018-04-25 23:11:24 +02:00
},
runner: function() {
2018-04-25 23:11:24 +02:00
return {
run: function() {
2018-04-25 23:11:24 +02:00
return {
catch: function(rethrow) {
rethrow.call(fakeInstance, error); // by calling here we're simulating that the promise was rejected
chai
.expect(error.stack)
.to.equal('Error: Some SQL error\nline1\nline2\nline3');
done();
2018-04-25 23:11:24 +02:00
},
then: function() {},
};
},
};
},
};
2018-04-25 23:11:24 +02:00
}
_interface(SomeClass);
const fakeInstance = new SomeClass();
chai.expect(fakeInstance[Symbol.toStringTag]).to.eq('object');
fakeInstance._asyncStack = ['line1', 'line2', 'line3'];
fakeInstance.then();
});
});