Giter Site home page Giter Site logo

Comments (9)

TheSavior avatar TheSavior commented on August 21, 2024 1

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.

TheSavior avatar TheSavior commented on August 21, 2024 1

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.

speedskater avatar speedskater commented on August 21, 2024

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.

valermor avatar valermor commented on August 21, 2024

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.

speedskater avatar speedskater commented on August 21, 2024

@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.

speedskater avatar speedskater commented on August 21, 2024

@valermor Did rewireing the class ifself help you?

from babel-plugin-rewire.

valermor avatar valermor commented on August 21, 2024

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.

TheSavior avatar TheSavior commented on August 21, 2024

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.

speedskater avatar speedskater commented on August 21, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.