Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

troubles injecting an exported function #157

Open
jcotero opened this issue Jan 30, 2019 · 0 comments
Open

troubles injecting an exported function #157

jcotero opened this issue Jan 30, 2019 · 0 comments

Comments

@jcotero
Copy link

jcotero commented Jan 30, 2019

Maybe I'm doing something wrong, I don't know... I'm trying to make an injection, but it seems it's not working.

I tried Stackoverflow before with no success: https://stackoverflow.com/questions/54443582/rewire-mocha-how-to-inject-a-function

So I'm trying to inject a mocked function in a module using Rewire.
I have a LotsRepo module with

const _incLot = async (params) => {
   // ...
}
exports.incLot = _incLot

Then, following this example, in a Mocha test I'm using:

let rewire = require('rewire')
var injections = {
    _incLot: async (params) => {
        throw new Error('mocked: findOneAndUpdate fake error!')
    }
}
const rewiredLotsRepo = rewire('./lotsRepo.js', null, injections)

And later, on an 'it' part, I'm calling:

let lot = await rewiredLotsRepo.incLot(params)

I was expecting to get the error. But instead, it's accessing the original incLot. What am I doing wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant