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

Invoking 'proxy' to generate test object but stub not invoked #140

Open
zlaroche opened this issue Sep 27, 2022 · 3 comments
Open

Invoking 'proxy' to generate test object but stub not invoked #140

zlaroche opened this issue Sep 27, 2022 · 3 comments

Comments

@zlaroche
Copy link

There must be something simple I'm doing wrong, but I can't figure it out.

A.js:

const { func } = require('./B')

const execFunc = () => {
  func();
}

module.exports = { execFunc }

B.js:

const func = () => {
  console.log("This is not the stubbed function");
}

module.exports = { func };

test.js:

const rewiremock = require('rewiremock/node');
rewiremock.overrideEntryPoint(module);

describe('rewiremock demonstration', () => {
  test('stub function with rewiremock', () => {
    
    const mockFunc = () => {
      console.log('This is the stubbed function')
    };

    const subject = rewiremock.proxy(
      () => require('./A'),
      () => {
        rewiremock(() => require('./B'))
          .with({ func: mockFunc })
      });
    subject.execFunc();
  })
})

output:

 This is not the stubbed function
@theKashey
Copy link
Owner

So what was the problem?

@zlaroche
Copy link
Author

I'm sorry, I should not have closed the issue. In my case I was able to get the mocking I needed working with sinon, but I still did not solve it for the code above.

@zlaroche zlaroche reopened this Sep 27, 2022
theKashey added a commit that referenced this issue Nov 13, 2022
@theKashey
Copy link
Owner

The code above works well. I've added test for "issue 140", but it's totally green

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

2 participants