-
Notifications
You must be signed in to change notification settings - Fork 19
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
Issue with partially mocking module that is also used within same file by another module #118
Comments
https://github.com/iambumblehead/esmock/blob/master/src/esmockModule.js#L53-L55 @vueme esmock currently does something like this paraphrased example, const originalFile = import( pathtooriginalfile );
const mockedFile = Object.assign({}, originalFile, mockDefinitions);
return mockedFile and so the partial mock won't work for your use-case (sorry) is it OK with you if this ticket is closed? |
Thanks for quick answer! You do not happen to have any workaround recommendation? Thanks anyways! |
@vueme these may not be great ideas but here they are :) One idea is to define both mock functions at the same time eg, const mock = {};
mock.funcTwo = () => 'mocked func two';
mock.funcOne = () => mock.funcTwo();
const supertestModule = await esmock.px('../modules/supertest.js', null, {
'../../../../server/troublesomeFile.js': mock
}) another idea is to use 'this' or some other namespace creatively like this export const obj = {};
obj.funcOne = async function () {
return 'this.funcOne'
};
obj.funcTwo = async function () {
return await this.funcOne();
}; originalfile-test.js const supertestModule = await esmock.px('../modules/supertest.js', null, {
'../../../../server/troublesomeFile.js': {
obj: {
...troublesomefile.obj,
funcOne: () => 'mocked value'
}
}
}) I didn't test these but hope their intention is expressed |
Thanks for the ideas and this great js package! I'll look into this. |
Hello.
I think I've found an issue. I'm having trouble with partially mocking deeply nested module that is also used in same file. Example below. I'm on Mocha and Node 17.4.0.
troublesomeFile.js
supertest.js (might not be relevant)
When funcTwoSameFile is called somewhere deeply nested in app.js, original version of funcOne is called and not the mocked one. Is this some kind of limitation or am i missing something? My other (full-module, not .px mocks) are working fine in other tests.
Thanks for your help!
The text was updated successfully, but these errors were encountered: