Thursday, 19 March 2020

How to make integration tests with a real database?

I need to test a PostgreSQL app using Jest, and I can't find an optimal solution for this. I could only find examples using Mongodb.What I am currently doing is using a pretest script that creates a test db with dataconst { Pool } = require('pg'); const { insertUsersQuery } = require('./users'); const connectionString = process.env.DATABASE_URL; const poll = new Pool({ connectionString, ssl: { rejectUnauthorized: false } }); (async () => { await poll.query(insertUsersQuery); await poll.query(insertTable2Query); await poll.query(insertTable3Query); ... await poll.end(); })(); Is there a better way to do this ?

Submitted March 19, 2020 at 06:04PM by A_NamelessRedditor

No comments:

Post a Comment