jest: Does not work with proxyquire

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

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 4
  • Comments: 15 (6 by maintainers)

Most upvoted comments

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

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.

It can, you can pass a third parameter

jest.mock('module', () => {}, {virtual: true})