Tuesday 23 May 2017

Can't get oracledb.createPool() to throw an error

I'm trying to do some unit testing on database code to make sure it is hitting every branch. This specific piece of code is causing me trouble. I've created a wrapper around the oracledb.createPool() function:

function createPool(config) {
    return new Promise(function(resolve, reject) {
        oracledb.createPool(
            config,
            function(error, pool) {
                if (error) {
                    console.log("TEST");
                    reject(error);
                } 

                dbPool = pool;
                resolve(dbPool);
            }
        );
    });
}

I'm doing my unit tests using jasmine-node. Here is the unit test I'm running:

describe("Creates a database connection pool", function() {
    it("should throw an error", function(done) {
        database.createPool(undefined) // calls my wrapper function
            .then(function() {
                done.fail();
            })
            .catch(function(err) {
                console.dir(err);
                expect(err).toBeDefined();
                done();
            });
    });
});

In the above code I'm passing in undefined to force oracledb.createPool to throw an error. My test case is actually "passing". I put passing in quotes because I'm not exactly sure why. The output from database.createPool is sent to the catch statement but does not go through the if statement in the wrapper function.

I'm still fairly new to nodejs, jasmine, and asynchronous programming in general, so it could be that I'm making an obvious mistake. Anyone have any thoughts on what the issue could be?



via Alex Cauthen

No comments:

Post a Comment