Comments (9)
I don't think it really makes sense to rewire instance methods and I don't believe rewire
does that either.
from babel-plugin-rewire.
You don't need rewire for this, you can just get the reference to your Class in your test and overwrite the function on the prototype. The value of rewire (and its family of packages) is to modify private state in modules that you would be otherwise unable to access.
Rewire should be the base package that simply enables private state and then lets other packages be built on top of it. That is why it is also important to not have this package diverge in any meaningful way from the standard rewire. Packages built on top of rewire should work with rewire, rewireify, rewire-global, and babel-plugin-rewire with no differences.
from babel-plugin-rewire.
Hi. Thanks for creating this issue. I think this should be supported. Can you create a PR with a sample containing your example. I will than have a look at it on thursday or friday.
from babel-plugin-rewire.
I am working on a project where supporting instance methods would be a great help.
@TheSavior can you elaborate why this case would not make sense beside whether being supported by rewire
?
from babel-plugin-rewire.
@TheSavior I totally agree.
@valermor Therefore if you have a case where it is not possible to rewire the class itself it is an issue for babel-plugin-rewire.
from babel-plugin-rewire.
@valermor Did rewireing the class ifself help you?
from babel-plugin-rewire.
Not really. The approach proposed by @TheSavior requires to have the class under test to expose its dependency in the API. I am not totally in favour of this.
I understand you do not want to alter the primary purpose of the module. However, it seems as if my case would be another use case which won't change the nature of the module but add a useful behaviour to it.
If there is an agreement that this needs to be dropped we can close the issue NP.
Otherwise, I can create a PR with the test.
Cheers.
from babel-plugin-rewire.
It seems like your use case is what sinon stubs are for. You could set a stub in your beforeEach, right?
from babel-plugin-rewire.
@valermor but changing the prototype of a member function should be possible (either directly or by creating a spy)?
Maybe a project building on top of rewire, babel-plugin-rewire or similar rewire libraries would be a solution to provide convencience functions for this. e.g. rewireClass(module, 'classname', { .... }).
This utilitiy/helper library could be combined with reset functionality which is than called in an afterEach function. So keeping the functionality of the plugin as simple as possible and providing additional functionality through a plugin? This should work together with my suggestion in this issue #26 (comment).
Could this be a solution?
from babel-plugin-rewire.
Related Issues (20)
- Broken bundles after upgrade to 1.2.0 HOT 1
- Error with `babel/preset-typescript` HOT 4
- How can I enable this for one module only? HOT 1
- Simply including this breaks lots of things
- Not working with jest, Invalid variable access: _get__ HOT 6
- Thanks for a great plugin! I'd suggest adding dynamic import syntax to the readme! :) HOT 2
- Windows 10 and Ubuntu output different code HOT 2
- can not work with element-ui
- Webpack bundle size increases dramatically with rewire HOT 1
- babel/plugin-transform-typescript and rewire HOT 1
- Documentation clarification
- Documentation clarification
- Documentation clarification HOT 1
- rewire seems to break `import * as foo from 'module'` HOT 1
- property names as variable names don't work in babel-plugin-rewire
- __Rewire__ is not a function HOT 1
- babel-plugin-rewire does not work in a Typescript project HOT 5
- Maintenance Request, is this repo actively maintained?
- Any plan to port this plugin to SWC?
- Integration with CRACO HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from babel-plugin-rewire.