diff --git a/CHANGELOG.md b/CHANGELOG.md index 92d9a9cd3fdc..e58676db857d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -71,6 +71,7 @@ - `[docs]` Removed useless expect.assertions in `TestingAsyncCode.md` ([#7131](https://github.com/facebook/jest/pull/7131)) - `[docs]` Remove references to `@providesModule` which isn't supported anymore ([#7147](https://github.com/facebook/jest/pull/7147)) - `[docs]` Update `setupFiles` documentation for clarity ([#7187](https://github.com/facebook/jest/pull/7187)) +- `[docs]` Change `require.require*` to `jest.require*` ([#7210](https://github.com/facebook/jest/pull/7210)) - `[jest-circus]` Add readme.md ([#7198](https://github.com/facebook/jest/pull/7198)) ### Performance diff --git a/docs/GlobalAPI.md b/docs/GlobalAPI.md index 0eb4f2be26d2..638856595e7b 100644 --- a/docs/GlobalAPI.md +++ b/docs/GlobalAPI.md @@ -434,14 +434,6 @@ test('will be ran', () => { }); ``` -### `require.requireActual(moduleName)` - -Returns the actual module instead of a mock, bypassing all checks on whether the module should receive a mock implementation or not. - -### `require.requireMock(moduleName)` - -Returns a mock module instead of the actual module, bypassing all checks on whether the module should be required normally or not. - ### `test(name, fn, timeout)` Also under the alias: `it(name, fn, timeout)` diff --git a/docs/JestObjectAPI.md b/docs/JestObjectAPI.md index 197d85cff252..0442c12a34e6 100644 --- a/docs/JestObjectAPI.md +++ b/docs/JestObjectAPI.md @@ -26,6 +26,8 @@ The `jest` object is automatically in scope within every test file. The methods - [`jest.runAllTimers()`](#jestrunalltimers) - [`jest.advanceTimersByTime(msToRun)`](#jestadvancetimersbytimemstorun) - [`jest.runOnlyPendingTimers()`](#jestrunonlypendingtimers) +- [`jest.requireActual()`](#jestrequireactual) +- [`jest.requireMock()`](#jestrequiremock) - [`jest.setMock(moduleName, moduleExports)`](#jestsetmockmodulename-moduleexports) - [`jest.setTimeout(timeout)`](#jestsettimeouttimeout) - [`jest.useFakeTimers()`](#jestusefaketimers) @@ -362,6 +364,14 @@ Executes only the macro-tasks that are currently pending (i.e., only the tasks t This is useful for scenarios such as one where the module being tested schedules a `setTimeout()` whose callback schedules another `setTimeout()` recursively (meaning the scheduling never stops). In these scenarios, it's useful to be able to run forward in time by a single step at a time. +### `jest.requireActual(moduleName)` + +Returns the actual module instead of a mock, bypassing all checks on whether the module should receive a mock implementation or not. + +### `jest.requireMock(moduleName)` + +Returns a mock module instead of the actual module, bypassing all checks on whether the module should be required normally or not. + ### `jest.setMock(moduleName, moduleExports)` Explicitly supplies the mock object that the module system should return for the specified module. diff --git a/docs/ManualMocks.md b/docs/ManualMocks.md index 554eb7bd6cb8..2d4f549f9c63 100644 --- a/docs/ManualMocks.md +++ b/docs/ManualMocks.md @@ -126,7 +126,7 @@ describe('listFilesInDirectorySync', () => { The example mock shown here uses [`jest.genMockFromModule`](JestObjectAPI.md#jestgenmockfrommodulemodulename) to generate an automatic mock, and overrides its default behavior. This is the recommended approach, but is completely optional. If you do not want to use the automatic mock at all, you can simply export your own functions from the mock file. One downside to fully manual mocks is that they're manual – meaning you have to manually update them any time the module they are mocking changes. Because of this, it's best to use or extend the automatic mock when it works for your needs. -To ensure that a manual mock and its real implementation stay in sync, it might be useful to require the real module using `require.requireActual(moduleName)` in your manual mock and amending it with mock functions before exporting it. +To ensure that a manual mock and its real implementation stay in sync, it might be useful to require the real module using `jest.requireActual(moduleName)` in your manual mock and amending it with mock functions before exporting it. The code for this example is available at [examples/manual-mocks](https://github.com/facebook/jest/tree/master/examples/manual-mocks). diff --git a/docs/Troubleshooting.md b/docs/Troubleshooting.md index d82a50ae9162..991133d283ab 100644 --- a/docs/Troubleshooting.md +++ b/docs/Troubleshooting.md @@ -144,7 +144,7 @@ If a promise doesn't resolve at all, this error might be thrown: - Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.` ``` -Most commonly this is being caused by conflicting Promise implementations. Consider replacing the global promise implementation with your own, for example `global.Promise = require.requireActual('promise');` and/or consolidate the used Promise libraries to a single one. +Most commonly this is being caused by conflicting Promise implementations. Consider replacing the global promise implementation with your own, for example `global.Promise = jest.requireActual('promise');` and/or consolidate the used Promise libraries to a single one. If your test is long running, you may want to consider to increase the timeout by calling `jest.setTimeout` diff --git a/docs/TutorialReactNative.md b/docs/TutorialReactNative.md index 1b7cb9f484e8..cab62656c318 100644 --- a/docs/TutorialReactNative.md +++ b/docs/TutorialReactNative.md @@ -185,7 +185,7 @@ Or if you'd like to create your own manual mock, you can do something like this: ```js jest.mock('Text', () => { - const RealComponent = require.requireActual('Text'); + const RealComponent = jest.requireActual('Text'); const React = require('React'); class Text extends React.Component { render() { diff --git a/e2e/__tests__/jest_require_actual.test.js b/e2e/__tests__/jest_require_actual.test.js index 6941eb645f89..e9fa4473fb03 100644 --- a/e2e/__tests__/jest_require_actual.test.js +++ b/e2e/__tests__/jest_require_actual.test.js @@ -19,11 +19,11 @@ const DIR = path.resolve(os.tmpdir(), 'jest_require_actual_test'); beforeEach(() => cleanup(DIR)); afterAll(() => cleanup(DIR)); -test('understands dependencies using require.requireActual', () => { +test('understands dependencies using jest.requireActual', () => { writeFiles(DIR, { '.watchmanconfig': '', '__tests__/a.test.js': ` - const a = require.requireActual('../a'); + const a = jest.requireActual('../a'); test('a', () => {}); `, diff --git a/e2e/__tests__/jest_require_mock.test.js b/e2e/__tests__/jest_require_mock.test.js index e2a8984d9619..040f2f69b8b0 100644 --- a/e2e/__tests__/jest_require_mock.test.js +++ b/e2e/__tests__/jest_require_mock.test.js @@ -19,11 +19,11 @@ const DIR = path.resolve(os.tmpdir(), 'jest_require_mock_test'); beforeEach(() => cleanup(DIR)); afterAll(() => cleanup(DIR)); -test('understands dependencies using require.requireMock', () => { +test('understands dependencies using jest.requireMock', () => { writeFiles(DIR, { '.watchmanconfig': '', '__tests__/a.test.js': ` - const a = require.requireMock('../a'); + const a = jest.requireMock('../a'); test('a', () => {}); `, diff --git a/examples/module-mock/__tests__/partial_mock.js b/examples/module-mock/__tests__/partial_mock.js index 40ba84dbdfd7..21077480ad1d 100644 --- a/examples/module-mock/__tests__/partial_mock.js +++ b/examples/module-mock/__tests__/partial_mock.js @@ -8,7 +8,7 @@ import defaultExport, {apple, strawberry} from '../fruit'; jest.mock('../fruit', () => { - const originalModule = require.requireActual('../fruit'); + const originalModule = jest.requireActual('../fruit'); const mockedModule = jest.genMockFromModule('../fruit'); //Mock the default export and named export 'apple'. diff --git a/packages/expect/src/__tests__/fake_chalk.test.js b/packages/expect/src/__tests__/fake_chalk.test.js index aab5def65c5c..c461b75c1b2d 100644 --- a/packages/expect/src/__tests__/fake_chalk.test.js +++ b/packages/expect/src/__tests__/fake_chalk.test.js @@ -6,7 +6,7 @@ */ 'use strict'; -const fakeChalk = require.requireActual('../fake_chalk'); +const fakeChalk = jest.requireActual('../fake_chalk'); describe('Fake Chalk', () => { it('returns input when invoked', () => { diff --git a/packages/jest-cli/src/__tests__/generateEmptyCoverage.test.js b/packages/jest-cli/src/__tests__/generateEmptyCoverage.test.js index 42dda61ca167..fe69dc6a43f4 100644 --- a/packages/jest-cli/src/__tests__/generateEmptyCoverage.test.js +++ b/packages/jest-cli/src/__tests__/generateEmptyCoverage.test.js @@ -15,7 +15,7 @@ const {makeGlobalConfig, makeProjectConfig} = require('../../../../TestUtils'); jest.mock('jest-runtime', () => { // $FlowFixMe requireActual - const realRuntime = require.requireActual('jest-runtime'); + const realRuntime = jest.requireActual('jest-runtime'); realRuntime.shouldInstrument = () => true; return realRuntime; }); diff --git a/packages/jest-config/src/__tests__/normalize.test.js b/packages/jest-config/src/__tests__/normalize.test.js index ff45c3036203..d8ed943adcb7 100644 --- a/packages/jest-config/src/__tests__/normalize.test.js +++ b/packages/jest-config/src/__tests__/normalize.test.js @@ -11,7 +11,7 @@ import normalize from '../normalize'; jest.mock('jest-resolve'); -jest.mock('path', () => require.requireActual('path').posix); +jest.mock('path', () => jest.requireActual('path').posix); const crypto = require('crypto'); const path = require('path'); @@ -1009,7 +1009,7 @@ describe('preset', () => { test('throws when preset is invalid', () => { jest.doMock('/node_modules/react-native/jest-preset.json', () => - require.requireActual('./jest-preset.json'), + jest.requireActual('./jest-preset.json'), ); expect(() => { @@ -1263,7 +1263,7 @@ describe('testPathPattern', () => { describe('win32', () => { beforeEach(() => { - jest.mock('path', () => require.requireActual('path').win32); + jest.mock('path', () => jest.requireActual('path').win32); require('jest-resolve').findNodeModule = findNodeModule; }); diff --git a/packages/jest-editor-support/src/__tests__/runner.test.js b/packages/jest-editor-support/src/__tests__/runner.test.js index 1f110a6bd72a..ad1999727583 100644 --- a/packages/jest-editor-support/src/__tests__/runner.test.js +++ b/packages/jest-editor-support/src/__tests__/runner.test.js @@ -14,7 +14,7 @@ jest.mock('child_process', () => ({spawn: jest.fn()})); jest.mock('os', () => ({tmpdir: jest.fn()})); jest.mock('fs', () => { // $FlowFixMe requireActual - const readFileSync = require.requireActual('fs').readFileSync; + const readFileSync = jest.requireActual('fs').readFileSync; // Replace `readFile` with `readFileSync` so we don't get multiple threads return { diff --git a/packages/jest-environment-jsdom/src/__mocks__/index.js b/packages/jest-environment-jsdom/src/__mocks__/index.js index 107546a83f2a..68f8411ac835 100644 --- a/packages/jest-environment-jsdom/src/__mocks__/index.js +++ b/packages/jest-environment-jsdom/src/__mocks__/index.js @@ -6,7 +6,7 @@ */ 'use strict'; -const vm = require.requireActual('vm'); +const vm = jest.requireActual('vm'); const JSDOMEnvironment = jest.genMockFromModule('../index'); diff --git a/packages/jest-environment-jsdom/src/__tests__/jsdom_environment.test.js b/packages/jest-environment-jsdom/src/__tests__/jsdom_environment.test.js index 47c73604a3ca..1f535f58a729 100644 --- a/packages/jest-environment-jsdom/src/__tests__/jsdom_environment.test.js +++ b/packages/jest-environment-jsdom/src/__tests__/jsdom_environment.test.js @@ -6,7 +6,7 @@ */ 'use strict'; -const JSDomEnvironment = require.requireActual('../'); +const JSDomEnvironment = jest.requireActual('../'); describe('JSDomEnvironment', () => { it('should configure setTimeout/setInterval to use the browser api', () => { diff --git a/packages/jest-environment-node/src/__tests__/node_environment.test.js b/packages/jest-environment-node/src/__tests__/node_environment.test.js index 2ad2955723ee..a4a434f4ef84 100644 --- a/packages/jest-environment-node/src/__tests__/node_environment.test.js +++ b/packages/jest-environment-node/src/__tests__/node_environment.test.js @@ -6,7 +6,7 @@ */ 'use strict'; -const NodeEnvironment = require.requireActual('../'); +const NodeEnvironment = jest.requireActual('../'); describe('NodeEnvironment', () => { it('uses a copy of the process object', () => { diff --git a/packages/jest-haste-map/src/lib/__tests__/normalize_path_sep.test.js b/packages/jest-haste-map/src/lib/__tests__/normalize_path_sep.test.js index 461177387404..c6ed861b54a7 100644 --- a/packages/jest-haste-map/src/lib/__tests__/normalize_path_sep.test.js +++ b/packages/jest-haste-map/src/lib/__tests__/normalize_path_sep.test.js @@ -12,14 +12,14 @@ describe('normalizePathSep', () => { it('does nothing on posix', () => { jest.resetModules(); - jest.mock('path', () => require.requireActual('path').posix); + jest.mock('path', () => jest.requireActual('path').posix); const normalizePathSep = require('../normalize_path_sep').default; expect(normalizePathSep('foo/bar/baz.js')).toEqual('foo/bar/baz.js'); }); it('replace slashes on windows', () => { jest.resetModules(); - jest.mock('path', () => require.requireActual('path').win32); + jest.mock('path', () => jest.requireActual('path').win32); const normalizePathSep = require('../normalize_path_sep').default; expect(normalizePathSep('foo/bar/baz.js')).toEqual('foo\\bar\\baz.js'); }); diff --git a/packages/jest-runtime/src/__tests__/script_transformer.test.js b/packages/jest-runtime/src/__tests__/script_transformer.test.js index da20831c6c18..60ae65c665ff 100644 --- a/packages/jest-runtime/src/__tests__/script_transformer.test.js +++ b/packages/jest-runtime/src/__tests__/script_transformer.test.js @@ -14,8 +14,8 @@ jest .mock('fs', () => // Node 10.5.x compatibility Object.assign({}, jest.genMockFromModule('fs'), { - ReadStream: require.requireActual('fs').ReadStream, - WriteStream: require.requireActual('fs').WriteStream, + ReadStream: jest.requireActual('fs').ReadStream, + WriteStream: jest.requireActual('fs').WriteStream, }), ) .mock('graceful-fs') @@ -23,7 +23,7 @@ jest getCacheFilePath: (cacheDir, baseDir, version) => cacheDir + baseDir, })) .mock('jest-util', () => { - const util = require.requireActual('jest-util'); + const util = jest.requireActual('jest-util'); util.createDirectory = jest.fn(); return util; }) diff --git a/packages/jest-runtime/src/__tests__/test_root/__mocks__/ManuallyMocked.js b/packages/jest-runtime/src/__tests__/test_root/__mocks__/ManuallyMocked.js index 8b2a0de29117..cbc163aee4d8 100644 --- a/packages/jest-runtime/src/__tests__/test_root/__mocks__/ManuallyMocked.js +++ b/packages/jest-runtime/src/__tests__/test_root/__mocks__/ManuallyMocked.js @@ -11,7 +11,7 @@ let OnlyRequiredFromMock; let moduleStateValue = 'default'; try { - OnlyRequiredFromMock = require.requireActual('OnlyRequiredFromMock'); + OnlyRequiredFromMock = jest.requireActual('OnlyRequiredFromMock'); } catch (e) { // If the module cannot be loaded, use a dummy value. There is one test // that specifically tests for the correct value which ensures this feature diff --git a/packages/jest-snapshot/src/__mocks__/prettier.js b/packages/jest-snapshot/src/__mocks__/prettier.js index 5c553328aa7f..ff89efde1bc4 100644 --- a/packages/jest-snapshot/src/__mocks__/prettier.js +++ b/packages/jest-snapshot/src/__mocks__/prettier.js @@ -1,4 +1,4 @@ -const prettier = require.requireActual('prettier'); +const prettier = jest.requireActual('prettier'); module.exports = { format: (text, opts) => diff --git a/packages/jest-util/src/__tests__/get_callsite.test.js b/packages/jest-util/src/__tests__/get_callsite.test.js index 7166d7a3a61b..da80a1de4433 100644 --- a/packages/jest-util/src/__tests__/get_callsite.test.js +++ b/packages/jest-util/src/__tests__/get_callsite.test.js @@ -5,8 +5,8 @@ import getCallsite from '../get_callsite'; // Node 10.5.x compatibility jest.mock('fs', () => Object.assign({}, jest.genMockFromModule('fs'), { - ReadStream: require.requireActual('fs').ReadStream, - WriteStream: require.requireActual('fs').WriteStream, + ReadStream: jest.requireActual('fs').ReadStream, + WriteStream: jest.requireActual('fs').WriteStream, }), ); diff --git a/website/versioned_docs/version-22.0/GlobalAPI.md b/website/versioned_docs/version-22.0/GlobalAPI.md index 5e0cd868a7b6..f7496d673a38 100644 --- a/website/versioned_docs/version-22.0/GlobalAPI.md +++ b/website/versioned_docs/version-22.0/GlobalAPI.md @@ -267,16 +267,6 @@ describe.skip('my other beverage', () => { }); ``` -Using `describe.skip` is often just an easier alternative to temporarily commenting out a chunk of tests. - -### `require.requireActual(moduleName)` - -Returns the actual module instead of a mock, bypassing all checks on whether the module should receive a mock implementation or not. - -### `require.requireMock(moduleName)` - -Returns a mock module instead of the actual module, bypassing all checks on whether the module should be required normally or not. - ### `test(name, fn, timeout)` Also under the alias: `it(name, fn, timeout)` diff --git a/website/versioned_docs/version-22.0/JestObjectAPI.md b/website/versioned_docs/version-22.0/JestObjectAPI.md index 4feb0d61c112..c897b6d4043c 100644 --- a/website/versioned_docs/version-22.0/JestObjectAPI.md +++ b/website/versioned_docs/version-22.0/JestObjectAPI.md @@ -26,6 +26,8 @@ The `jest` object is automatically in scope within every test file. The methods - [`jest.runAllTimers()`](#jestrunalltimers) - [`jest.advanceTimersByTime(msToRun)`](#jestadvancetimersbytimemstorun) - [`jest.runOnlyPendingTimers()`](#jestrunonlypendingtimers) +- [`jest.requireActual()`](#jestrequireactual) +- [`jest.requireMock()`](#jestrequiremock) - [`jest.setMock(moduleName, moduleExports)`](#jestsetmockmodulename-moduleexports) - [`jest.setTimeout(timeout)`](#jestsettimeouttimeout) - [`jest.useFakeTimers()`](#jestusefaketimers) @@ -266,6 +268,14 @@ Executes only the macro-tasks that are currently pending (i.e., only the tasks t This is useful for scenarios such as one where the module being tested schedules a `setTimeout()` whose callback schedules another `setTimeout()` recursively (meaning the scheduling never stops). In these scenarios, it's useful to be able to run forward in time by a single step at a time. +### `jest.requireActual(moduleName)` + +Returns the actual module instead of a mock, bypassing all checks on whether the module should receive a mock implementation or not. + +### `jest.requireMock(moduleName)` + +Returns a mock module instead of the actual module, bypassing all checks on whether the module should be required normally or not. + ### `jest.setMock(moduleName, moduleExports)` Explicitly supplies the mock object that the module system should return for the specified module. diff --git a/website/versioned_docs/version-22.0/ManualMocks.md b/website/versioned_docs/version-22.0/ManualMocks.md index ca744df2df3a..4987b6f636ff 100644 --- a/website/versioned_docs/version-22.0/ManualMocks.md +++ b/website/versioned_docs/version-22.0/ManualMocks.md @@ -111,7 +111,7 @@ describe('listFilesInDirectorySync', () => { The example mock shown here uses [`jest.genMockFromModule`](JestObjectAPI.md#jestgenmockfrommodulemodulename) to generate an automatic mock, and overrides its default behavior. This is the recommended approach, but is completely optional. If you do not want to use the automatic mock at all, you can simply export your own functions from the mock file. One downside to fully manual mocks is that they're manual – meaning you have to manually update them any time the module they are mocking changes. Because of this, it's best to use or extend the automatic mock when it works for your needs. -To ensure that a manual mock and its real implementation stay in sync, it might be useful to require the real module using `require.requireActual(moduleName)` in your manual mock and amending it with mock functions before exporting it. +To ensure that a manual mock and its real implementation stay in sync, it might be useful to require the real module using `jest.requireActual(moduleName)` in your manual mock and amending it with mock functions before exporting it. The code for this example is available at [examples/manual_mocks](https://github.com/facebook/jest/tree/master/examples/manual_mocks). diff --git a/website/versioned_docs/version-22.0/Troubleshooting.md b/website/versioned_docs/version-22.0/Troubleshooting.md index 9a4fbc0bfe0d..594e34733488 100644 --- a/website/versioned_docs/version-22.0/Troubleshooting.md +++ b/website/versioned_docs/version-22.0/Troubleshooting.md @@ -143,7 +143,7 @@ If a promise doesn't resolve at all, this error might be thrown: - Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.` ``` -Most commonly this is being caused by conflicting Promise implementations. Consider replacing the global promise implementation with your own, for example `global.Promise = require.requireActual('promise');` and/or consolidate the used Promise libraries to a single one. +Most commonly this is being caused by conflicting Promise implementations. Consider replacing the global promise implementation with your own, for example `global.Promise = jest.requireActual('promise');` and/or consolidate the used Promise libraries to a single one. If your test is long running, you may want to consider to increase the timeout by calling `jest.setTimeout` diff --git a/website/versioned_docs/version-22.0/TutorialReactNative.md b/website/versioned_docs/version-22.0/TutorialReactNative.md index 0df325074e23..275cacbc7df4 100644 --- a/website/versioned_docs/version-22.0/TutorialReactNative.md +++ b/website/versioned_docs/version-22.0/TutorialReactNative.md @@ -188,7 +188,7 @@ Or if you'd like to create your own manual mock, you can do something like this: ```js jest.mock('Text', () => { - const RealComponent = require.requireActual('Text'); + const RealComponent = jest.requireActual('Text'); const React = require('React'); class Text extends React.Component { render() { diff --git a/website/versioned_docs/version-22.1/JestObjectAPI.md b/website/versioned_docs/version-22.1/JestObjectAPI.md index 762c064ce479..0bccfffd50f5 100644 --- a/website/versioned_docs/version-22.1/JestObjectAPI.md +++ b/website/versioned_docs/version-22.1/JestObjectAPI.md @@ -26,6 +26,8 @@ The `jest` object is automatically in scope within every test file. The methods - [`jest.runAllTimers()`](#jestrunalltimers) - [`jest.advanceTimersByTime(msToRun)`](#jestadvancetimersbytimemstorun) - [`jest.runOnlyPendingTimers()`](#jestrunonlypendingtimers) +- [`jest.requireActual()`](#jestrequireactual) +- [`jest.requireMock()`](#jestrequiremock) - [`jest.setMock(moduleName, moduleExports)`](#jestsetmockmodulename-moduleexports) - [`jest.setTimeout(timeout)`](#jestsettimeouttimeout) - [`jest.useFakeTimers()`](#jestusefaketimers) @@ -264,6 +266,14 @@ Executes only the macro-tasks that are currently pending (i.e., only the tasks t This is useful for scenarios such as one where the module being tested schedules a `setTimeout()` whose callback schedules another `setTimeout()` recursively (meaning the scheduling never stops). In these scenarios, it's useful to be able to run forward in time by a single step at a time. +### `jest.requireActual(moduleName)` + +Returns the actual module instead of a mock, bypassing all checks on whether the module should receive a mock implementation or not. + +### `jest.requireMock(moduleName)` + +Returns a mock module instead of the actual module, bypassing all checks on whether the module should be required normally or not. + ### `jest.setMock(moduleName, moduleExports)` Explicitly supplies the mock object that the module system should return for the specified module. diff --git a/website/versioned_docs/version-22.1/Troubleshooting.md b/website/versioned_docs/version-22.1/Troubleshooting.md index d532c3ba00b6..7f1e409b7c21 100644 --- a/website/versioned_docs/version-22.1/Troubleshooting.md +++ b/website/versioned_docs/version-22.1/Troubleshooting.md @@ -143,7 +143,7 @@ If a promise doesn't resolve at all, this error might be thrown: - Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.` ``` -Most commonly this is being caused by conflicting Promise implementations. Consider replacing the global promise implementation with your own, for example `global.Promise = require.requireActual('promise');` and/or consolidate the used Promise libraries to a single one. +Most commonly this is being caused by conflicting Promise implementations. Consider replacing the global promise implementation with your own, for example `global.Promise = jest.requireActual('promise');` and/or consolidate the used Promise libraries to a single one. If your test is long running, you may want to consider to increase the timeout by calling `jest.setTimeout` diff --git a/website/versioned_docs/version-22.1/TutorialReactNative.md b/website/versioned_docs/version-22.1/TutorialReactNative.md index b6c93d0f60ce..31afb5ea156d 100644 --- a/website/versioned_docs/version-22.1/TutorialReactNative.md +++ b/website/versioned_docs/version-22.1/TutorialReactNative.md @@ -188,7 +188,7 @@ Or if you'd like to create your own manual mock, you can do something like this: ```js jest.mock('Text', () => { - const RealComponent = require.requireActual('Text'); + const RealComponent = jest.requireActual('Text'); const React = require('React'); class Text extends React.Component { render() { diff --git a/website/versioned_docs/version-22.2/GlobalAPI.md b/website/versioned_docs/version-22.2/GlobalAPI.md index 985881ee2679..49aad8c1c9f5 100644 --- a/website/versioned_docs/version-22.2/GlobalAPI.md +++ b/website/versioned_docs/version-22.2/GlobalAPI.md @@ -269,14 +269,6 @@ describe.skip('my other beverage', () => { Using `describe.skip` is often just an easier alternative to temporarily commenting out a chunk of tests. -### `require.requireActual(moduleName)` - -Returns the actual module instead of a mock, bypassing all checks on whether the module should receive a mock implementation or not. - -### `require.requireMock(moduleName)` - -Returns a mock module instead of the actual module, bypassing all checks on whether the module should be required normally or not. - ### `test(name, fn, timeout)` Also under the alias: `it(name, fn, timeout)` diff --git a/website/versioned_docs/version-22.2/JestObjectAPI.md b/website/versioned_docs/version-22.2/JestObjectAPI.md index 3da280fe409f..8991484ca9b2 100644 --- a/website/versioned_docs/version-22.2/JestObjectAPI.md +++ b/website/versioned_docs/version-22.2/JestObjectAPI.md @@ -26,6 +26,8 @@ The `jest` object is automatically in scope within every test file. The methods - [`jest.runAllTimers()`](#jestrunalltimers) - [`jest.advanceTimersByTime(msToRun)`](#jestadvancetimersbytimemstorun) - [`jest.runOnlyPendingTimers()`](#jestrunonlypendingtimers) +- [`jest.requireActual()`](#jestrequireactual) +- [`jest.requireMock()`](#jestrequiremock) - [`jest.setMock(moduleName, moduleExports)`](#jestsetmockmodulename-moduleexports) - [`jest.setTimeout(timeout)`](#jestsettimeouttimeout) - [`jest.useFakeTimers()`](#jestusefaketimers) @@ -265,6 +267,14 @@ Executes only the macro-tasks that are currently pending (i.e., only the tasks t This is useful for scenarios such as one where the module being tested schedules a `setTimeout()` whose callback schedules another `setTimeout()` recursively (meaning the scheduling never stops). In these scenarios, it's useful to be able to run forward in time by a single step at a time. +### `jest.requireActual(moduleName)` + +Returns the actual module instead of a mock, bypassing all checks on whether the module should receive a mock implementation or not. + +### `jest.requireMock(moduleName)` + +Returns a mock module instead of the actual module, bypassing all checks on whether the module should be required normally or not. + ### `jest.setMock(moduleName, moduleExports)` Explicitly supplies the mock object that the module system should return for the specified module. diff --git a/website/versioned_docs/version-22.2/ManualMocks.md b/website/versioned_docs/version-22.2/ManualMocks.md index bf71735a9e2e..10b545e4d77b 100644 --- a/website/versioned_docs/version-22.2/ManualMocks.md +++ b/website/versioned_docs/version-22.2/ManualMocks.md @@ -111,7 +111,7 @@ describe('listFilesInDirectorySync', () => { The example mock shown here uses [`jest.genMockFromModule`](JestObjectAPI.md#jestgenmockfrommodulemodulename) to generate an automatic mock, and overrides its default behavior. This is the recommended approach, but is completely optional. If you do not want to use the automatic mock at all, you can simply export your own functions from the mock file. One downside to fully manual mocks is that they're manual – meaning you have to manually update them any time the module they are mocking changes. Because of this, it's best to use or extend the automatic mock when it works for your needs. -To ensure that a manual mock and its real implementation stay in sync, it might be useful to require the real module using `require.requireActual(moduleName)` in your manual mock and amending it with mock functions before exporting it. +To ensure that a manual mock and its real implementation stay in sync, it might be useful to require the real module using `jest.requireActual(moduleName)` in your manual mock and amending it with mock functions before exporting it. The code for this example is available at [examples/manual_mocks](https://github.com/facebook/jest/tree/master/examples/manual_mocks). diff --git a/website/versioned_docs/version-22.2/Troubleshooting.md b/website/versioned_docs/version-22.2/Troubleshooting.md index 013063088d7d..3ab403f26717 100644 --- a/website/versioned_docs/version-22.2/Troubleshooting.md +++ b/website/versioned_docs/version-22.2/Troubleshooting.md @@ -143,7 +143,7 @@ If a promise doesn't resolve at all, this error might be thrown: - Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.` ``` -Most commonly this is being caused by conflicting Promise implementations. Consider replacing the global promise implementation with your own, for example `global.Promise = require.requireActual('promise');` and/or consolidate the used Promise libraries to a single one. +Most commonly this is being caused by conflicting Promise implementations. Consider replacing the global promise implementation with your own, for example `global.Promise = jest.requireActual('promise');` and/or consolidate the used Promise libraries to a single one. If your test is long running, you may want to consider to increase the timeout by calling `jest.setTimeout` diff --git a/website/versioned_docs/version-22.2/TutorialReactNative.md b/website/versioned_docs/version-22.2/TutorialReactNative.md index fd105e41858a..97c541158583 100644 --- a/website/versioned_docs/version-22.2/TutorialReactNative.md +++ b/website/versioned_docs/version-22.2/TutorialReactNative.md @@ -188,7 +188,7 @@ Or if you'd like to create your own manual mock, you can do something like this: ```js jest.mock('Text', () => { - const RealComponent = require.requireActual('Text'); + const RealComponent = jest.requireActual('Text'); const React = require('React'); class Text extends React.Component { render() { diff --git a/website/versioned_docs/version-22.3/GlobalAPI.md b/website/versioned_docs/version-22.3/GlobalAPI.md index dc33a5a5b4b4..d30da4a0aec4 100644 --- a/website/versioned_docs/version-22.3/GlobalAPI.md +++ b/website/versioned_docs/version-22.3/GlobalAPI.md @@ -269,14 +269,6 @@ describe.skip('my other beverage', () => { Using `describe.skip` is often just an easier alternative to temporarily commenting out a chunk of tests. -### `require.requireActual(moduleName)` - -Returns the actual module instead of a mock, bypassing all checks on whether the module should receive a mock implementation or not. - -### `require.requireMock(moduleName)` - -Returns a mock module instead of the actual module, bypassing all checks on whether the module should be required normally or not. - ### `test(name, fn, timeout)` Also under the alias: `it(name, fn, timeout)` diff --git a/website/versioned_docs/version-22.3/JestObjectAPI.md b/website/versioned_docs/version-22.3/JestObjectAPI.md index d9c61f926299..8705bac90005 100644 --- a/website/versioned_docs/version-22.3/JestObjectAPI.md +++ b/website/versioned_docs/version-22.3/JestObjectAPI.md @@ -26,6 +26,8 @@ The `jest` object is automatically in scope within every test file. The methods - [`jest.runAllTimers()`](#jestrunalltimers) - [`jest.advanceTimersByTime(msToRun)`](#jestadvancetimersbytimemstorun) - [`jest.runOnlyPendingTimers()`](#jestrunonlypendingtimers) +- [`jest.requireActual()`](#jestrequireactual) +- [`jest.requireMock()`](#jestrequiremock) - [`jest.setMock(moduleName, moduleExports)`](#jestsetmockmodulename-moduleexports) - [`jest.setTimeout(timeout)`](#jestsettimeouttimeout) - [`jest.useFakeTimers()`](#jestusefaketimers) @@ -265,6 +267,14 @@ Executes only the macro-tasks that are currently pending (i.e., only the tasks t This is useful for scenarios such as one where the module being tested schedules a `setTimeout()` whose callback schedules another `setTimeout()` recursively (meaning the scheduling never stops). In these scenarios, it's useful to be able to run forward in time by a single step at a time. +### `jest.requireActual(moduleName)` + +Returns the actual module instead of a mock, bypassing all checks on whether the module should receive a mock implementation or not. + +### `jest.requireMock(moduleName)` + +Returns a mock module instead of the actual module, bypassing all checks on whether the module should be required normally or not. + ### `jest.setMock(moduleName, moduleExports)` Explicitly supplies the mock object that the module system should return for the specified module. diff --git a/website/versioned_docs/version-22.3/ManualMocks.md b/website/versioned_docs/version-22.3/ManualMocks.md index 092e9778d7c0..2f757a7ab910 100644 --- a/website/versioned_docs/version-22.3/ManualMocks.md +++ b/website/versioned_docs/version-22.3/ManualMocks.md @@ -111,7 +111,7 @@ describe('listFilesInDirectorySync', () => { The example mock shown here uses [`jest.genMockFromModule`](JestObjectAPI.md#jestgenmockfrommodulemodulename) to generate an automatic mock, and overrides its default behavior. This is the recommended approach, but is completely optional. If you do not want to use the automatic mock at all, you can simply export your own functions from the mock file. One downside to fully manual mocks is that they're manual – meaning you have to manually update them any time the module they are mocking changes. Because of this, it's best to use or extend the automatic mock when it works for your needs. -To ensure that a manual mock and its real implementation stay in sync, it might be useful to require the real module using `require.requireActual(moduleName)` in your manual mock and amending it with mock functions before exporting it. +To ensure that a manual mock and its real implementation stay in sync, it might be useful to require the real module using `jest.requireActual(moduleName)` in your manual mock and amending it with mock functions before exporting it. The code for this example is available at [examples/manual_mocks](https://github.com/facebook/jest/tree/master/examples/manual_mocks). diff --git a/website/versioned_docs/version-22.3/Troubleshooting.md b/website/versioned_docs/version-22.3/Troubleshooting.md index 0d6e281e1ea8..fa72233755bb 100644 --- a/website/versioned_docs/version-22.3/Troubleshooting.md +++ b/website/versioned_docs/version-22.3/Troubleshooting.md @@ -143,7 +143,7 @@ If a promise doesn't resolve at all, this error might be thrown: - Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.` ``` -Most commonly this is being caused by conflicting Promise implementations. Consider replacing the global promise implementation with your own, for example `global.Promise = require.requireActual('promise');` and/or consolidate the used Promise libraries to a single one. +Most commonly this is being caused by conflicting Promise implementations. Consider replacing the global promise implementation with your own, for example `global.Promise = jest.requireActual('promise');` and/or consolidate the used Promise libraries to a single one. If your test is long running, you may want to consider to increase the timeout by calling `jest.setTimeout` diff --git a/website/versioned_docs/version-22.3/TutorialReactNative.md b/website/versioned_docs/version-22.3/TutorialReactNative.md index a3e91e3823f3..04e8d37f84b1 100644 --- a/website/versioned_docs/version-22.3/TutorialReactNative.md +++ b/website/versioned_docs/version-22.3/TutorialReactNative.md @@ -186,7 +186,7 @@ Or if you'd like to create your own manual mock, you can do something like this: ```js jest.mock('Text', () => { - const RealComponent = require.requireActual('Text'); + const RealComponent = jest.requireActual('Text'); const React = require('React'); class Text extends React.Component { render() { diff --git a/website/versioned_docs/version-22.4/JestObjectAPI.md b/website/versioned_docs/version-22.4/JestObjectAPI.md index cb1c90d86b1e..383c5faab39d 100644 --- a/website/versioned_docs/version-22.4/JestObjectAPI.md +++ b/website/versioned_docs/version-22.4/JestObjectAPI.md @@ -26,6 +26,8 @@ The `jest` object is automatically in scope within every test file. The methods - [`jest.runAllTimers()`](#jestrunalltimers) - [`jest.advanceTimersByTime(msToRun)`](#jestadvancetimersbytimemstorun) - [`jest.runOnlyPendingTimers()`](#jestrunonlypendingtimers) +- [`jest.requireActual()`](#jestrequireactual) +- [`jest.requireMock()`](#jestrequiremock) - [`jest.setMock(moduleName, moduleExports)`](#jestsetmockmodulename-moduleexports) - [`jest.setTimeout(timeout)`](#jestsettimeouttimeout) - [`jest.useFakeTimers()`](#jestusefaketimers) @@ -347,6 +349,14 @@ Executes only the macro-tasks that are currently pending (i.e., only the tasks t This is useful for scenarios such as one where the module being tested schedules a `setTimeout()` whose callback schedules another `setTimeout()` recursively (meaning the scheduling never stops). In these scenarios, it's useful to be able to run forward in time by a single step at a time. +### `jest.requireActual(moduleName)` + +Returns the actual module instead of a mock, bypassing all checks on whether the module should receive a mock implementation or not. + +### `jest.requireMock(moduleName)` + +Returns a mock module instead of the actual module, bypassing all checks on whether the module should be required normally or not. + ### `jest.setMock(moduleName, moduleExports)` Explicitly supplies the mock object that the module system should return for the specified module. diff --git a/website/versioned_docs/version-22.4/ManualMocks.md b/website/versioned_docs/version-22.4/ManualMocks.md index 32ccde0a8205..e59535949c96 100644 --- a/website/versioned_docs/version-22.4/ManualMocks.md +++ b/website/versioned_docs/version-22.4/ManualMocks.md @@ -125,7 +125,7 @@ describe('listFilesInDirectorySync', () => { The example mock shown here uses [`jest.genMockFromModule`](JestObjectAPI.md#jestgenmockfrommodulemodulename) to generate an automatic mock, and overrides its default behavior. This is the recommended approach, but is completely optional. If you do not want to use the automatic mock at all, you can simply export your own functions from the mock file. One downside to fully manual mocks is that they're manual – meaning you have to manually update them any time the module they are mocking changes. Because of this, it's best to use or extend the automatic mock when it works for your needs. -To ensure that a manual mock and its real implementation stay in sync, it might be useful to require the real module using `require.requireActual(moduleName)` in your manual mock and amending it with mock functions before exporting it. +To ensure that a manual mock and its real implementation stay in sync, it might be useful to require the real module using `jest.requireActual(moduleName)` in your manual mock and amending it with mock functions before exporting it. The code for this example is available at [examples/manual-mocks](https://github.com/facebook/jest/tree/master/examples/manual-mocks). diff --git a/website/versioned_docs/version-22.4/Troubleshooting.md b/website/versioned_docs/version-22.4/Troubleshooting.md index 4297243b24ce..b1aafc20e45d 100644 --- a/website/versioned_docs/version-22.4/Troubleshooting.md +++ b/website/versioned_docs/version-22.4/Troubleshooting.md @@ -143,7 +143,7 @@ If a promise doesn't resolve at all, this error might be thrown: - Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.` ``` -Most commonly this is being caused by conflicting Promise implementations. Consider replacing the global promise implementation with your own, for example `global.Promise = require.requireActual('promise');` and/or consolidate the used Promise libraries to a single one. +Most commonly this is being caused by conflicting Promise implementations. Consider replacing the global promise implementation with your own, for example `global.Promise = jest.requireActual('promise');` and/or consolidate the used Promise libraries to a single one. If your test is long running, you may want to consider to increase the timeout by calling `jest.setTimeout` diff --git a/website/versioned_docs/version-22.4/TutorialReactNative.md b/website/versioned_docs/version-22.4/TutorialReactNative.md index 2c98ad425484..43edc1c882d2 100644 --- a/website/versioned_docs/version-22.4/TutorialReactNative.md +++ b/website/versioned_docs/version-22.4/TutorialReactNative.md @@ -186,7 +186,7 @@ Or if you'd like to create your own manual mock, you can do something like this: ```js jest.mock('Text', () => { - const RealComponent = require.requireActual('Text'); + const RealComponent = jest.requireActual('Text'); const React = require('React'); class Text extends React.Component { render() { diff --git a/website/versioned_docs/version-23.0/GlobalAPI.md b/website/versioned_docs/version-23.0/GlobalAPI.md index 90b230680e4c..0b0a350c178a 100644 --- a/website/versioned_docs/version-23.0/GlobalAPI.md +++ b/website/versioned_docs/version-23.0/GlobalAPI.md @@ -429,14 +429,6 @@ test('will be ran', () => { }); ``` -### `require.requireActual(moduleName)` - -Returns the actual module instead of a mock, bypassing all checks on whether the module should receive a mock implementation or not. - -### `require.requireMock(moduleName)` - -Returns a mock module instead of the actual module, bypassing all checks on whether the module should be required normally or not. - ### `test(name, fn, timeout)` Also under the alias: `it(name, fn, timeout)` diff --git a/website/versioned_docs/version-23.0/JestObjectAPI.md b/website/versioned_docs/version-23.0/JestObjectAPI.md index 8f3b459aac4e..b962638c922c 100644 --- a/website/versioned_docs/version-23.0/JestObjectAPI.md +++ b/website/versioned_docs/version-23.0/JestObjectAPI.md @@ -26,6 +26,8 @@ The `jest` object is automatically in scope within every test file. The methods - [`jest.runAllTimers()`](#jestrunalltimers) - [`jest.advanceTimersByTime(msToRun)`](#jestadvancetimersbytimemstorun) - [`jest.runOnlyPendingTimers()`](#jestrunonlypendingtimers) +- [`jest.requireActual()`](#jestrequireactual) +- [`jest.requireMock()`](#jestrequiremock) - [`jest.setMock(moduleName, moduleExports)`](#jestsetmockmodulename-moduleexports) - [`jest.setTimeout(timeout)`](#jestsettimeouttimeout) - [`jest.useFakeTimers()`](#jestusefaketimers) @@ -347,6 +349,14 @@ Executes only the macro-tasks that are currently pending (i.e., only the tasks t This is useful for scenarios such as one where the module being tested schedules a `setTimeout()` whose callback schedules another `setTimeout()` recursively (meaning the scheduling never stops). In these scenarios, it's useful to be able to run forward in time by a single step at a time. +### `jest.requireActual(moduleName)` + +Returns the actual module instead of a mock, bypassing all checks on whether the module should receive a mock implementation or not. + +### `jest.requireMock(moduleName)` + +Returns a mock module instead of the actual module, bypassing all checks on whether the module should be required normally or not. + ### `jest.setMock(moduleName, moduleExports)` Explicitly supplies the mock object that the module system should return for the specified module. diff --git a/website/versioned_docs/version-23.0/ManualMocks.md b/website/versioned_docs/version-23.0/ManualMocks.md index 15f181bd1b82..85290bb25b62 100644 --- a/website/versioned_docs/version-23.0/ManualMocks.md +++ b/website/versioned_docs/version-23.0/ManualMocks.md @@ -127,7 +127,7 @@ describe('listFilesInDirectorySync', () => { The example mock shown here uses [`jest.genMockFromModule`](JestObjectAPI.md#jestgenmockfrommodulemodulename) to generate an automatic mock, and overrides its default behavior. This is the recommended approach, but is completely optional. If you do not want to use the automatic mock at all, you can simply export your own functions from the mock file. One downside to fully manual mocks is that they're manual – meaning you have to manually update them any time the module they are mocking changes. Because of this, it's best to use or extend the automatic mock when it works for your needs. -To ensure that a manual mock and its real implementation stay in sync, it might be useful to require the real module using `require.requireActual(moduleName)` in your manual mock and amending it with mock functions before exporting it. +To ensure that a manual mock and its real implementation stay in sync, it might be useful to require the real module using `jest.requireActual(moduleName)` in your manual mock and amending it with mock functions before exporting it. The code for this example is available at [examples/manual-mocks](https://github.com/facebook/jest/tree/master/examples/manual-mocks). diff --git a/website/versioned_docs/version-23.0/Troubleshooting.md b/website/versioned_docs/version-23.0/Troubleshooting.md index 729b06fdfda8..aaff878d9f56 100644 --- a/website/versioned_docs/version-23.0/Troubleshooting.md +++ b/website/versioned_docs/version-23.0/Troubleshooting.md @@ -143,7 +143,7 @@ If a promise doesn't resolve at all, this error might be thrown: - Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.` ``` -Most commonly this is being caused by conflicting Promise implementations. Consider replacing the global promise implementation with your own, for example `global.Promise = require.requireActual('promise');` and/or consolidate the used Promise libraries to a single one. +Most commonly this is being caused by conflicting Promise implementations. Consider replacing the global promise implementation with your own, for example `global.Promise = jest.requireActual('promise');` and/or consolidate the used Promise libraries to a single one. If your test is long running, you may want to consider to increase the timeout by calling `jest.setTimeout` diff --git a/website/versioned_docs/version-23.1/JestObjectAPI.md b/website/versioned_docs/version-23.1/JestObjectAPI.md index ed72108e5a30..700bf9bc85a0 100644 --- a/website/versioned_docs/version-23.1/JestObjectAPI.md +++ b/website/versioned_docs/version-23.1/JestObjectAPI.md @@ -26,6 +26,8 @@ The `jest` object is automatically in scope within every test file. The methods - [`jest.runAllTimers()`](#jestrunalltimers) - [`jest.advanceTimersByTime(msToRun)`](#jestadvancetimersbytimemstorun) - [`jest.runOnlyPendingTimers()`](#jestrunonlypendingtimers) +- [`jest.requireActual()`](#jestrequireactual) +- [`jest.requireMock()`](#jestrequiremock) - [`jest.setMock(moduleName, moduleExports)`](#jestsetmockmodulename-moduleexports) - [`jest.setTimeout(timeout)`](#jestsettimeouttimeout) - [`jest.useFakeTimers()`](#jestusefaketimers) @@ -347,6 +349,14 @@ Executes only the macro-tasks that are currently pending (i.e., only the tasks t This is useful for scenarios such as one where the module being tested schedules a `setTimeout()` whose callback schedules another `setTimeout()` recursively (meaning the scheduling never stops). In these scenarios, it's useful to be able to run forward in time by a single step at a time. +### `jest.requireActual(moduleName)` + +Returns the actual module instead of a mock, bypassing all checks on whether the module should receive a mock implementation or not. + +### `jest.requireMock(moduleName)` + +Returns a mock module instead of the actual module, bypassing all checks on whether the module should be required normally or not. + ### `jest.setMock(moduleName, moduleExports)` Explicitly supplies the mock object that the module system should return for the specified module. diff --git a/website/versioned_docs/version-23.2/GlobalAPI.md b/website/versioned_docs/version-23.2/GlobalAPI.md index 8cd941755365..d91ddc7b12a0 100644 --- a/website/versioned_docs/version-23.2/GlobalAPI.md +++ b/website/versioned_docs/version-23.2/GlobalAPI.md @@ -432,14 +432,6 @@ test('will be ran', () => { }); ``` -### `require.requireActual(moduleName)` - -Returns the actual module instead of a mock, bypassing all checks on whether the module should receive a mock implementation or not. - -### `require.requireMock(moduleName)` - -Returns a mock module instead of the actual module, bypassing all checks on whether the module should be required normally or not. - ### `test(name, fn, timeout)` Also under the alias: `it(name, fn, timeout)` diff --git a/website/versioned_docs/version-23.2/JestObjectAPI.md b/website/versioned_docs/version-23.2/JestObjectAPI.md index 039c1293432b..dce067532b37 100644 --- a/website/versioned_docs/version-23.2/JestObjectAPI.md +++ b/website/versioned_docs/version-23.2/JestObjectAPI.md @@ -26,6 +26,8 @@ The `jest` object is automatically in scope within every test file. The methods - [`jest.runAllTimers()`](#jestrunalltimers) - [`jest.advanceTimersByTime(msToRun)`](#jestadvancetimersbytimemstorun) - [`jest.runOnlyPendingTimers()`](#jestrunonlypendingtimers) +- [`jest.requireActual()`](#jestrequireactual) +- [`jest.requireMock()`](#jestrequiremock) - [`jest.setMock(moduleName, moduleExports)`](#jestsetmockmodulename-moduleexports) - [`jest.setTimeout(timeout)`](#jestsettimeouttimeout) - [`jest.useFakeTimers()`](#jestusefaketimers) @@ -347,6 +349,14 @@ Executes only the macro-tasks that are currently pending (i.e., only the tasks t This is useful for scenarios such as one where the module being tested schedules a `setTimeout()` whose callback schedules another `setTimeout()` recursively (meaning the scheduling never stops). In these scenarios, it's useful to be able to run forward in time by a single step at a time. +### `jest.requireActual(moduleName)` + +Returns the actual module instead of a mock, bypassing all checks on whether the module should receive a mock implementation or not. + +### `jest.requireMock(moduleName)` + +Returns a mock module instead of the actual module, bypassing all checks on whether the module should be required normally or not. + ### `jest.setMock(moduleName, moduleExports)` Explicitly supplies the mock object that the module system should return for the specified module. diff --git a/website/versioned_docs/version-23.3/JestObjectAPI.md b/website/versioned_docs/version-23.3/JestObjectAPI.md index fdb912b600f8..f11e24388bb7 100644 --- a/website/versioned_docs/version-23.3/JestObjectAPI.md +++ b/website/versioned_docs/version-23.3/JestObjectAPI.md @@ -27,6 +27,8 @@ The `jest` object is automatically in scope within every test file. The methods - [`jest.runAllTimers()`](#jestrunalltimers) - [`jest.advanceTimersByTime(msToRun)`](#jestadvancetimersbytimemstorun) - [`jest.runOnlyPendingTimers()`](#jestrunonlypendingtimers) +- [`jest.requireActual()`](#jestrequireactual) +- [`jest.requireMock()`](#jestrequiremock) - [`jest.setMock(moduleName, moduleExports)`](#jestsetmockmodulename-moduleexports) - [`jest.setTimeout(timeout)`](#jestsettimeouttimeout) - [`jest.useFakeTimers()`](#jestusefaketimers) @@ -363,6 +365,14 @@ Executes only the macro-tasks that are currently pending (i.e., only the tasks t This is useful for scenarios such as one where the module being tested schedules a `setTimeout()` whose callback schedules another `setTimeout()` recursively (meaning the scheduling never stops). In these scenarios, it's useful to be able to run forward in time by a single step at a time. +### `jest.requireActual(moduleName)` + +Returns the actual module instead of a mock, bypassing all checks on whether the module should receive a mock implementation or not. + +### `jest.requireMock(moduleName)` + +Returns a mock module instead of the actual module, bypassing all checks on whether the module should be required normally or not. + ### `jest.setMock(moduleName, moduleExports)` Explicitly supplies the mock object that the module system should return for the specified module. diff --git a/website/versioned_docs/version-23.5/GlobalAPI.md b/website/versioned_docs/version-23.5/GlobalAPI.md index 756992220d08..c40afbf63d29 100644 --- a/website/versioned_docs/version-23.5/GlobalAPI.md +++ b/website/versioned_docs/version-23.5/GlobalAPI.md @@ -435,14 +435,6 @@ test('will be ran', () => { }); ``` -### `require.requireActual(moduleName)` - -Returns the actual module instead of a mock, bypassing all checks on whether the module should receive a mock implementation or not. - -### `require.requireMock(moduleName)` - -Returns a mock module instead of the actual module, bypassing all checks on whether the module should be required normally or not. - ### `test(name, fn, timeout)` Also under the alias: `it(name, fn, timeout)` diff --git a/website/versioned_docs/version-23.6/Troubleshooting.md b/website/versioned_docs/version-23.6/Troubleshooting.md index 1698f4814aa2..82e4960fb156 100644 --- a/website/versioned_docs/version-23.6/Troubleshooting.md +++ b/website/versioned_docs/version-23.6/Troubleshooting.md @@ -145,7 +145,7 @@ If a promise doesn't resolve at all, this error might be thrown: - Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.` ``` -Most commonly this is being caused by conflicting Promise implementations. Consider replacing the global promise implementation with your own, for example `global.Promise = require.requireActual('promise');` and/or consolidate the used Promise libraries to a single one. +Most commonly this is being caused by conflicting Promise implementations. Consider replacing the global promise implementation with your own, for example `global.Promise = jest.requireActual('promise');` and/or consolidate the used Promise libraries to a single one. If your test is long running, you may want to consider to increase the timeout by calling `jest.setTimeout`