Does not work with proxyquire
See original GitHub issueDo 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:
- Created 7 years ago
- Reactions:4
- Comments:15 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.htmlThats 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.