I found some responses for this problem but they don't work with promises probably. I want to clear DB after each test. I am trying to save id
from request response and collect/pass it to afterEach
. Unfortunatelly, promise doesn't override value and it's null as defined.
describe('Should check DB setup', () => {
let value;
let request = chai.request('http://localhost:81')
.post('/api/report')
.send(mock);
let db = require(process.env.DB_DRIVER)(process.env.DB_NAME);
it('Checks do DB has table', () => {
request
.then((res) => {
let query = db.prepare('PRAGMA table_info('+process.env.ORDERS_TABLE+')').get();
db.close();
value = 'Win Later';
expect(query).is.not.a('undefined');
});
});
afterEach(() => {
console.log(value); //undefined
});
});