vendredi 29 janvier 2016

Mock an anonymous function using proxyquire with Node.js?

Is it possible to mock an anonymous function using proxyquire with Node.js? I have a module I need to mock whose constructor is an anonymous class. Is it possible to use proxyquire to mock this, or is there another way to do this?

The reason I'm using proxyquire is because it's a module that is 'required' by the file I'm writing unit tests for.

An example of the code and the function that is returned is:

var example = require('example')(config);

This returns an anonymous function that takes in config as parameters.

function (config) { return new Example(config); }

Aucun commentaire:

Enregistrer un commentaire