Giter VIP home page Giter VIP logo

Comments (4)

boblauer avatar boblauer commented on June 27, 2024

This is not possible currently, as you are correct that it assumes a string is a file path.

I would suggest making a dummy-template.html file instead.

from mock-require.

Owlbertz avatar Owlbertz commented on June 27, 2024

Having a dummy template is what I am currently doing, but as my project has a rather dynamic structure, this leads to issues during building and testing (using gulp), as files get copied to different locations.

If you think is is a valid feature request, I will try to do a PR.

from mock-require.

boblauer avatar boblauer commented on June 27, 2024

Unfortunately I don't think this would be a good feature to add, as it would hide errors when referencing an incorrect path/module. For example, mock('./file.js', './otherr-file.js') would "return" the string ./otherr-file.js, rather than alerting the user that ./otherr-file.js does not exist.

Depending on how your code is setup, you might be able to get away with doing something like:

const html = {
  toString: () => '<html />'
};

mock('./template.html', html);

require('./template.html') will now return an object, but if that object is coerced into a string later on, then it will work just as if it were a string. It's a bit of a hack, but it may work for you depending on how this html string is being used later on in the code.

from mock-require.

Owlbertz avatar Owlbertz commented on June 27, 2024

I actually tried that, but it failed as toString() was not invoked in my case.
I guess I will just find a way to copy the templates to where they are searched as well.

from mock-require.

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.