thlorenz / proxyquire

🔮 Proxies nodejs require in order to allow overriding dependencies during testing.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can we stub pg library of nodejs using proxyquire?

Saini01Basu opened this issue · comments

Below is the stub i have written for pg Client. But looks like it is calling the actual connect method of pg Client and not the stubbed method -

describe("System ID validation", function() {
        // System ID should exist in VSC DB
        it("Failed to connect to VSC DB", function() {
            let pgStub = {
                Client: function(host) {
                  this.connect = function(callback) {
                    return callback('Error connecting to VSC DB');
                  };
                }
              };
              let proxiedBD = proxyquire("../blackduck", { 'pg': pgStub });
        
              proxiedBD.validate_system_id(function(err, data){
                expect(err).to.deep.equal('Error: Failed connecting to VSC DB');
                done();
              });
        })
 })

Have resolved it