Giter VIP home page Giter VIP logo

Comments (9)

raine avatar raine commented on July 29, 2024 2

I think it would be great if the README had at least one example for stubbing a module that exports a single function directly. It's such a common use-case.

from proxyquire.

kirbysayshi avatar kirbysayshi commented on July 29, 2024

I was able to get a "primitive" mocked by doing:

var mocked = proxyquire('./path/to/thing', {
  'path/to/primitive': (function() {
    var s = new String('foo');
    s['@global'] = true; // probably not necessary for your example, but I needed this
    return s;
  }()),
});

If you don't need the global mock, you could probably just use:

var mocked = proxyquire('./path/to/thing', {
  'path/to/primitive': new String('foo')
});

It's not 100% the same, but for me it was close enough.

from proxyquire.

ninjatronic avatar ninjatronic commented on July 29, 2024

@kirbysayshi fair enough, but worth noting that this way won't work for any module that exports a number or a boolean value

from proxyquire.

thlorenz avatar thlorenz commented on July 29, 2024

@ninjatronic the above suggestion solves your problem right?
Do you really have cases where you export a number? I'm not sure if there are enough cases to make it worth supporting in proxyquire.

@kirbysayshi could you please add your solution to this wiki page? I'll link it from the readme once you do.

Thanks.

from proxyquire.

kirbysayshi avatar kirbysayshi commented on July 29, 2024

@thlorenz done! Any feedback is very appreciated

from proxyquire.

thlorenz avatar thlorenz commented on July 29, 2024

Thanks @kirbysayshi. Looks good.
Once @ninjatronic's PR makes it in, we may not need any caveats anymore as primitives will just work then.

from proxyquire.

thlorenz avatar thlorenz commented on July 29, 2024

PR landed

from proxyquire.

ninjatronic avatar ninjatronic commented on July 29, 2024

@thlorenz thanks :)

from proxyquire.

thlorenz avatar thlorenz commented on July 29, 2024

@raine PRs welcome :)

from proxyquire.

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.