lundi 28 novembre 2016

Stubs and proxquire

I'm having an issue with stubbing a particular function with sinon after having used proxyquire.

Example:

// a.js
const api = require('api');

module.exports = (function () {
    return {
        run,
        doStuff
    };

    function run() {
        return api()
            .then((data) => {
                return doStuff(data);
            })
    }

    function doStuff(data) {
        return `Got data: ${data}`;
    }
})()

// a.spec.js - in the test
a = proxyquire('./a', {
    'api': () => Promise.resolve('data')
})
sinon.stub(a, 'doStuff');
// RUN TEST - call a.run()

I know it isn't working because it calls the original c instead of a mocked/stubbed c.

Aucun commentaire:

Enregistrer un commentaire