Tuesday 26 May 2020

Why doesn't my test run my middleware with db.connect?

I have a middleware that I want to test and it contains a database connection.// register.js module.exports = (req, resp) => { db.connect((err, client, done) => { if (err) console.log(err); (async() => { try { await client.query('BEGIN') /* create user account */ await client.query('COMMIT') .then(() => { console.log('sending response'); resp.status(201).end(); }); } catch (e) { throw e; } finally { done(); } })() .catch(err => console.log(err)); }); } The test never reaches the console.log and there is no new row in my test database. Here is my test.describe('test registration', () => { it('will create a new account', (done) => { register(req, resp); // done(); }); }); I've tried using done after register() without result. I also notice the same problem when I use the request library to make a request to google recaptcha. Is there something I don't know about async operations like these?

Submitted May 26, 2020 at 12:11PM by eggtart_prince

No comments:

Post a Comment