UNPKG

rewiremock

Version:

Advanced dependency mocking device.

24 lines (18 loc) 601 B
import createPlugin, { PASS, NO } from './_common'; import getScope from '../globals'; import { isParent, getModuleName } from '../module'; var shouldMock = function shouldMock(mock, request, parent, topModule) { if (mock.flag_directChildOnly) { return isParent(parent, topModule) ? PASS : NO; } if (mock.flag_toBeCalledFromMock) { var _getScope = getScope(), mockedModules = _getScope.mockedModules; return getModuleName(parent) in mockedModules ? PASS : NO; } }; var plugin = createPlugin({ shouldMock: shouldMock, name: 'directChild' }); export default plugin;