thlorenz/proxyquire

Mocks the first require only

Closed this issue · 1 comments

It looks like proxyquire mocks the first module override only.

        const mymodule = proxyquire( 'my_module', 
            {
                './first': { 
                    do(){ } 
                } 
            } ,

            { 
                './second': { 
                    do(){   } 
                } 
            } 
        )

In this example, do() in the first override is called, but second's no is not. If I switch these around

        const mymodule = proxyquire( 'my_module', 
            {
                './second': { 
                    do(){ } 
                } 
            } ,

            { 
                './first': { 
                    do(){   } 
                } 
            } 
        )

then second's do is called, and first's is not. Based on the documentation I would assume that both modules would be overridden.

Proxyquire takes two arguments, the path to the module under test, and a stubs object.

https://github.com/thlorenz/proxyquire#api

You are passing multiple objects. Only the first one is consumed as stubs.