Monday, 2 July 2018

Testing With IoC

I'm quite new to Node and learning the ropes as I go along. I'm trying to test the following code:async connectToDb(connectionDetails) { let client = new this.pg.Client(connectionDetails) client.connect() .catch(err => console.error('connection error', err.stack)) return client; } I'm trying to get a passing test which returns a client instance. In another language such as PHP, I would use an IoC library to make a DI for the client instance. This will allow me to mock the 'connect' method.I've seen the InverstiyJs which will allow me to achieve the same feat. However, I've seen in this sub that it's frowned upon by some to use it as it isn't the 'Node way' while not providing any alternatives.What would be the node way to tackle this problem?

Submitted July 02, 2018 at 11:58AM by WonderCode

No comments:

Post a Comment