0
moduleOne :건너 뛰기
const moduleTwo = require('moduleTwo'); //moduleTwo opens Websocket
module.exports = {
functionToTest:() => 1
}
지금 내가 그 기능을 테스트 할 - test.js를 : 문제는
const tap = require('tap');
const moduleOne = require('moduleOne');
tap.equal(moduleOne.functionToTest(),1);
, 그 moduleTwo에서 몇 가지 코드 websocket이 열리고 테스트가 끝나지 않습니다.
테스트하는 동안 moduleTwo가 필요한 moduleOne을 어떻게 방지합니까?
const tap = require('tap');
mock('moduleTwo', {
// export whatever you need, just don't open websockets
});
// now moduleOne will require your mock instead of real moduleTwo
const moduleOne = require('moduleOne');
tap.equal(moduleOne.functionToTest(),1);
을 또는 당신은 moduleTwo
몇 가지 옵션을 추가 할 수 있지만 그것이 사용되는 모든 장소 변경이 필요합니다 :
moduleOne 내보내기 내에서 moduleTwo를 요구할지 여부를 결정하는 옵션을 추가하십시오. 그런 다음 moduleOne이 필요할 때 몇 가지 옵션을 전달합니다. – yBrodsky