Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does proxyquire handle second level (indirect) requires of proxies modules?

If we have three modules names A, B and C so module A requires B and B requires C: what would be the effect of this call?

var A = proxyquire('A', {'C': mockedModule})

Would module B get the mock or the real C module?

like image 998
fortran Avatar asked May 29 '14 23:05

fortran


1 Answers

Only direct dependencies will be mocked.

But you can nest proxyquire statements, so in your example you could:

const A = proxyquire('../A', {
    './B': proxyquire('../B', {
        'C': mockC
    })
});

Where the file structure is like

root
 |-- A.js
 |-- B.js
 `-- tests
       `-- A.spec.js

And import C is not local.

like image 192
Wolfshead Avatar answered Nov 05 '22 04:11

Wolfshead