knex/test/unit/util/save-async-stack.js

33 lines
872 B
JavaScript
Raw Normal View History

2018-04-25 23:11:24 +02:00
'use strict';
2019-07-10 22:48:43 +01:00
const saveAsyncStack = require('../../../lib/util/save-async-stack');
const chai = require('chai');
2018-04-25 23:11:24 +02:00
2020-04-19 00:40:23 +02:00
describe('saveAsyncStack', function () {
it('should store an error stack on passed object', function () {
const fakeInstance = {
2018-04-25 23:11:24 +02:00
client: {
config: {
asyncStackTraces: true,
},
},
};
saveAsyncStack(fakeInstance, 1);
2018-04-25 23:11:24 +02:00
const { error, lines } = fakeInstance._asyncStack;
const stackByLines = error.stack.split('\n');
const asyncStack = stackByLines.slice(lines);
chai.expect(asyncStack[0]).to.match(/at saveAsyncStack /);
});
2018-04-25 23:11:24 +02:00
2020-04-19 00:40:23 +02:00
it('should not store an error stack when config is disabled', function () {
const fakeInstance = {
2018-04-25 23:11:24 +02:00
client: {
config: {},
},
};
saveAsyncStack(fakeInstance, 1);
chai.expect(fakeInstance._asyncStack).to.be.undefined;
});
});