Monday, 5 February 2018

How do you mock dependencies for integration tests?

There seems to be a lot of modules available to mock dependencies (mockery, mock-require, rewire, proxyquire...) but I can't seem to find the right one. I'm using chai-http + mocha and integration testing a Koa server. I want to start the server at the beginning of the test suite, and then mock deep dependencies depending on the test.Example:Server starts, imports A, A imports B, B imports C. During testing I want to mock out C for a test so it returns something on a function call. Ideally I could use sinon to verify the function was called with certain arguments.The issue I'm having is the imports get cached and I can't break it. I've tried the various "mock.reRequire" and other such functions but no luck. Ideally I wouldn't have to flush the module cache on every single test.

Submitted February 05, 2018 at 08:32PM by mrjking

No comments:

Post a Comment