question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Does not work with proxyquire

See original GitHub issue

Do you want to request a feature or report a bug? bug

What is the current behavior? doesn’t work with proxyquire

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal repository on GitHub that we can npm install and npm test. repro repo: https://github.com/kentor/proxyquire-jest

> npm test
 FAIL  __tests__/index-test.js
  ● index › test

    TypeError: Cannot read property 'bind' of undefined

      at Proxyquire.Object.<anonymous>.Proxyquire.load (node_modules/proxyquire/lib/proxyquire.js:136:79)
      at Object.it (__tests__/index-test.js:6:19)
      at process._tickCallback (internal/process/next_tick.js:103:7)

  index
    ✕ test (4ms)

works with mocha: npm run mocha.

What is the expected behavior? to work

Run Jest again with --debug and provide the full configuration it prints. Please mention your node and npm version and operating system. node: 6.8.0 npm: 3.10.8

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:4
  • Comments:15 (3 by maintainers)

github_iconTop GitHub Comments

13reactions
cpojercommented, Oct 17, 2016

Proxyquire is not necessary with Jest. Jest brings its own require implementation and you can stub out modules using jest.mock and similar. See http://facebook.github.io/jest/docs/api.html

12reactions
theKasheycommented, Nov 23, 2017

Thats was not a perfect answer. It is better to say - Jest sanboxing system does not allow any third-party mocking system to coexists. And it does include some sort of mocking, by the way.

https://github.com/theKashey/rewiremock does supports proxyquire-like syntax, and it could work inside Jest environment. But proxyquire and 99.9% other mocking libs cant bypass Jest’s systems.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Proxyquire not stubbing my required class - Stack Overflow
The answer as to why this is happening is as follows. proxyquire still requires the underlying code before stubbing it out.
Read more >
Can not get proxyquire to work with a require that happens in ...
I have some code like this: /lib/mine.js const path = require('path'); function init(cfg) { var inner = require(cfg.file); inner.
Read more >
Please, stop playing with proxyquire | by Anton Korzunov
But I would say — no. It has nothing with dependency mocking. I urge you — stop using rewire . Yes - it's...
Read more >
Using proxyquire and sinon for unit testing in Node.js
Speeds up testing; Easier to identify problems; More secure (due to not sharing production API credentials with CI environment).
Read more >
proxyquire - npm
By default proxyquire calls the function defined on the original dependency whenever it is not found on the stub.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found