Giter VIP home page Giter VIP logo

Comments (12)

zakgrant avatar zakgrant commented on June 22, 2024

I too am finding that with node 8 the mocks are not being reset on calling stop / stopAll

from mock-require.

boblauer avatar boblauer commented on June 22, 2024

@zakgrant Node 8 or 8.5? I'm seeing a big difference between how require works internally from 8 to 8.5.

from mock-require.

zakgrant avatar zakgrant commented on June 22, 2024

@boblauer yeah I am using node 8.5

from mock-require.

alexpchin avatar alexpchin commented on June 22, 2024

I've got a similar issue... but I don't think it's with my version of node. I have something going on where some of the files stop mocking and some don't?

I use setup my mocks in a spec_helper file that gets loaded before running my express app, like so:

mock('../../lib/docusign', '../../libmocks/docusign_mock');

and then in the test for the that specific lib file, I do:

  before(() => {
    mock.stop('../../lib/docusign');
    docusign = require('../../lib/docusign');
  });

  after(() => {
    mock('../../lib/docusign', '../../libmocks/docusign_mock');
  });

With the goal of mocking with fixtures for everything apart from testing the file itself.
It seems to work with some of the lib files but not others?

from mock-require.

robertmain avatar robertmain commented on June 22, 2024

Not sure if it's related or not, but I'm finding that it's not catching module import statements if I import * as fs from 'fs'. Is it supposed to work with import as well?

from mock-require.

boblauer avatar boblauer commented on June 22, 2024

@alexpchin I think you're right that that is unrelated. Do you mind opening a new issue, with possibly a sample project that reproduces the issue?

@robertmain It does not work with native import statements. If your code is being transpiled by babel, for example, then it should work, because those import statements actually get converted to require statements. However, it's a bit more complex than that.

I would recommend you take a look at https://babeljs.io/repl/#?babili=false&browsers=&build=&builtIns=false&code_lz=Q&debug=false&circleciRepo=&evaluate=true&lineWrap=false&presets=es2015%2Creact%2Cstage-2&targets=&version=6.26.0 to see what your code is actually being converted to, I suspect the issue might be in the conversion itself.

from mock-require.

robertmain avatar robertmain commented on June 22, 2024

Well my code is TypeScript so, it is running through a transpiler(just not Babel). However it seems not to be working with that.

from mock-require.

bobbyg603 avatar bobbyg603 commented on June 22, 2024

I'm also having this issue in node 8.5 :/. Anyone have a workaround?

from mock-require.

robertmain avatar robertmain commented on June 22, 2024

@bobbyg603 I ended up using a different package(mock-fs) instead`

from mock-require.

mightyiam avatar mightyiam commented on June 22, 2024

This is still an issue with latest version, 3.0.1.
https://travis-ci.org/mightyiam/mock-path-with-simple-spy/jobs/328199961#L1872

from mock-require.

mightyiam avatar mightyiam commented on June 22, 2024

Still an issue. See failing CI here:
mightyiam/mock-path-with-simple-spy#29

from mock-require.

patrick99e99 avatar patrick99e99 commented on June 22, 2024

Still an issue for me 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.