How to unit test a Node.js module that requires other modules and how to mock the global require function?

后端 未结 8 2092
我在风中等你
我在风中等你 2020-11-29 16:38

This is a trivial example that illustrates the crux of my problem:

var innerLib = require(\'./path/to/innerLib\');

function underTest() {
    return innerLi         


        
8条回答
  •  广开言路
    2020-11-29 17:37

    I use mock-require. Make sure you define your mocks before you require the module to be tested.

提交回复
热议问题