Pretty simple question, whether or not it can be answered I don't know. Issue is im running some tests to verify whether or not I connected to a postgres database using mocha. I'm returning a value from my client.connect() however its undefined and obviously is giving me errors. So the question is what does client.connect for pg node return. If you have another method I could implement to test connection I would love to hear it as well.
This is pretty close and I would use it though Im not sure how they are validating whether its passing or not since I want my test to fail when I dont pass the correct data but does pass when I send the correct data.
connectToTable: async function (client) {
client = client || new Client({
user: "my_user",
host: "postgres",
database: "my_database",
password: "password123",
port: 5432,
max: 20,
idleTimeoutMillis: 30000,
connectionTimeoutMillis: 2000,
});
let resp = await client.connect()
await expect(JSON.stringify(resp)).to.not.contain('Error');
done()
Here is what Im doing. and the error is.
AssertionError: object tested must be an array, a map, an object, a set,
a string, or a weakset, but undefined given
I've tried messing around with printing it out but I'm not even sure what to print out so the JSON stringify is just there from me messing around with different ideas.
So Im open to different testing methods. Or an explanation of how the example I gave of another stack overflow works so that I can design my test like that. Any help is appreciated
Connect is asynchronous and awaitable. So, to be awaitable, the underlying function must return a promise. So, connect returns a promise.