knex/test/unit/builder-interface-augmenter.js

45 lines
1.2 KiB
JavaScript
Raw Normal View History

2018-04-25 23:11:24 +02:00
'use strict';
const {
augmentWithBuilderInterface,
} = require('../../lib/builder-interface-augmenter');
const chai = require('chai');
2018-04-25 23:11:24 +02:00
2020-04-19 00:40:23 +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
},
2020-04-19 00:40:23 +02:00
runner: function () {
2018-04-25 23:11:24 +02:00
return {
2020-04-19 00:40:23 +02:00
run: function () {
2018-04-25 23:11:24 +02:00
return {
2020-04-19 00:40:23 +02:00
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
},
2020-04-19 00:40:23 +02:00
then: function () {},
};
},
};
},
};
2018-04-25 23:11:24 +02:00
}
augmentWithBuilderInterface(SomeClass);
const fakeInstance = new SomeClass();
chai.expect(fakeInstance[Symbol.toStringTag]).to.eq('object');
fakeInstance._asyncStack = {
error: { stack: 'line1\nline2\nline3' },
lines: 0,
};
fakeInstance.then();
});
});