How to use the jest-cli/src/lib/moduleMocker.getMockFunction function in jest-cli

To help you get started, we’ve selected a few jest-cli examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github 60frames / jestpack / ModuleLoader.js View on Github external
getTestEnvData: () => {
                const frozenCopy = {};
                // Make a shallow copy only because a deep copy seems like
                // overkill..
                Object.keys(this._config.testEnvData).forEach(key => {
                    frozenCopy[key] = this._config.testEnvData[key];
                }, this);
                Object.freeze(frozenCopy);
                return frozenCopy;
            },

            genMockFromModule: moduleId => this._generateMock(moduleId, true),

            genMockFunction: moduleMocker.getMockFunction,

            genMockFn: moduleMocker.getMockFunction,

            mock: moduleId => {
                this._explicitShouldMock[moduleId] = true;
                return runtime;
            },

            /* eslint-disable */
            resetModuleRegistry: () => {
                const envGlobal = this._environment.global;
                Object.keys(envGlobal).forEach(key => {
                    const globalMock = envGlobal[key];
                    if ((typeof globalMock === 'object' && globalMock !== null) ||
                        typeof globalMock === 'function') {
                        globalMock._isMockFunction && globalMock.mockClear();
                    }
                });
github 60frames / jestpack / ModuleLoader.js View on Github external
// This isn't documented...
            getTestEnvData: () => {
                const frozenCopy = {};
                // Make a shallow copy only because a deep copy seems like
                // overkill..
                Object.keys(this._config.testEnvData).forEach(key => {
                    frozenCopy[key] = this._config.testEnvData[key];
                }, this);
                Object.freeze(frozenCopy);
                return frozenCopy;
            },

            genMockFromModule: moduleId => this._generateMock(moduleId, true),

            genMockFunction: moduleMocker.getMockFunction,

            genMockFn: moduleMocker.getMockFunction,

            mock: moduleId => {
                this._explicitShouldMock[moduleId] = true;
                return runtime;
            },

            /* eslint-disable */
            resetModuleRegistry: () => {
                const envGlobal = this._environment.global;
                Object.keys(envGlobal).forEach(key => {
                    const globalMock = envGlobal[key];
                    if ((typeof globalMock === 'object' && globalMock !== null) ||
                        typeof globalMock === 'function') {
                        globalMock._isMockFunction && globalMock.mockClear();