Giter VIP home page Giter VIP logo

Comments (7)

franciscop avatar franciscop commented on June 27, 2024

Seems like Jest has a .mock() method so I will be using that. Sorry for bothering you :)

from mock-require.

boblauer avatar boblauer commented on June 27, 2024

Not a bother at all. For anyone else who sees this, I'm guessing the issue here is that Jest is probably using its own custom require method, which is how it handles things like auto-mocking. But as you discovered, you can just use Jest's mocking functionality and bypass mock-require altogether.

from mock-require.

JasoonS avatar JasoonS commented on June 27, 2024

@boblauer I really enjoy using your library. I use it in a bff (backend for frontend) that I have for a UI I am building and it works great.

I usually run the bff in 'mocked' mode independently and that works perfectly, but I would like to run it in mocked mode for my jest tests. This causes problems, and I can't seem to find a way to get jest to mock modules that are deeper in my file hierarchy (like your library does beautifully).

I tried mocking the 'mock-require' function with the jest.mock (or jest.doMock or jest.setMock) but it doesn't seem to work when it is an external file.

Maybe you have some suggestions? Otherwise I'll just run the bff in a separate thread when I run my tests.

from mock-require.

boblauer avatar boblauer commented on June 27, 2024

Unfortunately I don't have any experience with using this library in parallel with Jest, so I'm afraid I don't have any suggestions on how to make it work. Sorry ☚ī¸

from mock-require.

JasoonS avatar JasoonS commented on June 27, 2024

Thanks for the reply. :) I'll have to make do!

from mock-require.

NateZimmer avatar NateZimmer commented on June 27, 2024

Your mocking lib was beautifully intuitive and I was using it w/ mocha. Unfortunately I hate mocha so I was trying to move onto Jest. Unfortunately it didn't work there and Jest's mock lib for modules is not nearly as intuitive or elegant as yours. So, nice work on the lib 👍

from mock-require.

boblauer avatar boblauer commented on June 27, 2024

Thank you for the kind words @NateZimmer . It's a bummer it doesn't work with Jest.

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.