diff --git a/CHANGELOG.md b/CHANGELOG.md index 70e8cc9f51d4..49ee07a674a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## master +## main ### Features @@ -2138,7 +2138,7 @@ We skipped 24.2.0 because a draft was accidentally published. Please use `24.3.0 - Fix inconsistent name of complex values in pretty-format ([#4001](https://github.com/facebook/jest/pull/4001)) - Fix issue mocking bound method ([#3805](https://github.com/facebook/jest/pull/3805)) - Fix jest-circus ([#4290](https://github.com/facebook/jest/pull/4290)) -- Fix lint warning in master +- Fix lint warning in main ([#4132](https://github.com/facebook/jest/pull/4132)) @@ -2240,7 +2240,7 @@ We skipped 24.2.0 because a draft was accidentally published. Please use `24.3.0 - Support maxDepth option in React plugins ([#4208](https://github.com/facebook/jest/pull/4208)) - Support SVG elements in HTMLElement plugin ([#4335](https://github.com/facebook/jest/pull/4335)) - Test empty Immutable collections with {min: false} option ([#4121](https://github.com/facebook/jest/pull/4121)) -- test to debug travis failure in master ([#4145](https://github.com/facebook/jest/pull/4145)) +- test to debug travis failure in main ([#4145](https://github.com/facebook/jest/pull/4145)) - testPathPattern message test ([#4006](https://github.com/facebook/jest/pull/4006)) - Throw Error When Using Nested It Specs ([#4039](https://github.com/facebook/jest/pull/4039)) - Throw when moduleNameMapper points to inexistent module ([#3567](https://github.com/facebook/jest/pull/3567)) @@ -2430,7 +2430,7 @@ See https://jestjs.io/blog/2016/12/15/2016-in-jest - Renamed `--jsonOutputFile` to `--outputFile`. - Added `jest-editor-support` for vscode and Nuclide integration. - Fixed `test.concurrent` unhandled promise rejections. -- The Jest website is now auto-deployed when merging into master. +- The Jest website is now auto-deployed when merging into main. - Updated `testRegex` to include `test.js` and `spec.js` files. - Fixes for `babel-plugin-jest-hoist` when using `jest.mock` with three arguments. - The `JSON` global in `jest-environment-node` now comes from the vm context instead of the parent context. @@ -2751,7 +2751,7 @@ See https://jestjs.io/blog/2016/12/15/2016-in-jest - Fixed a memory leak with test contexts. Jest now properly cleans up test environments after each test. Added `--logHeapUsage` to log memory usage after each test. Note: this is option is meant for debugging memory leaks and might significantly slow down your test run. - Removed `mock-modules`, `node-haste` and `mocks` virtual modules. This is a breaking change of undocumented public API. Usage of this API can safely be automatically updated through an automated codemod: - Example: http://astexplorer.net/#/zrybZ6UvRA -- Codemod: https://github.com/cpojer/js-codemod/blob/master/transforms/jest-update.js +- Codemod: https://github.com/cpojer/js-codemod/blob/main/transforms/jest-update.js - jscodeshift: https://github.com/facebook/jscodeshift - Removed `navigator.onLine` and `mockSetReadOnlyProperty` from the global jsdom environment. Use `window.navigator.onLine = true;` in your test setup and `Object.defineProperty` instead. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ec955bce27a1..08bae3d7ba7c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,9 +10,9 @@ Facebook has adopted a Code of Conduct that we expect project participants to ad All work on Jest happens directly on [GitHub](/). Both core team members and external contributors send pull requests which go through the same review process. -### `master` is unsafe +### `main` is unsafe -We will do our best to keep `master` in good shape, with tests passing at all times. But in order to move fast, we will make API changes that your application might not be compatible with. We will do our best to communicate these changes and always version appropriately so you can lock into a specific version if need be. +We will do our best to keep `main` in good shape, with tests passing at all times. But in order to move fast, we will make API changes that your application might not be compatible with. We will do our best to communicate these changes and always version appropriately so you can lock into a specific version if need be. ### Workflow and Pull Requests @@ -20,7 +20,7 @@ The core team will be monitoring for pull requests. When we get one, we'll run s _Before_ submitting a pull request, please make sure the following is done… -1. Fork the repo and create your branch from `master`. A guide on how to fork a repository: https://help.github.com/articles/fork-a-repo/ +1. Fork the repo and create your branch from `main`. A guide on how to fork a repository: https://help.github.com/articles/fork-a-repo/ Open terminal (e.g. Terminal, iTerm, Git Bash or Git Shell) and type: diff --git a/README.md b/README.md index bbe87e0f48e3..c8a46fcb7581 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@

npm version - + Jest is released under the MIT license. Follow on Twitter diff --git a/docs/Configuration.md b/docs/Configuration.md index 58c1d6133852..de70e3cdbebd 100644 --- a/docs/Configuration.md +++ b/docs/Configuration.md @@ -234,7 +234,7 @@ _Note: You can pass additional options to the istanbul reporter using the tuple ["json", ["lcov", {"projectRoot": "../../"}]] ``` -For the additional information about the options object shape you can refer to `CoverageReporterWithOptions` type in the [type definitions](https://github.com/facebook/jest/tree/master/packages/jest-types/src/Config.ts). +For the additional information about the options object shape you can refer to `CoverageReporterWithOptions` type in the [type definitions](https://github.com/facebook/jest/tree/main/packages/jest-types/src/Config.ts). ### `coverageThreshold` \[object] @@ -765,7 +765,7 @@ class MyCustomReporter { } ``` -For the full list of methods and argument types see `Reporter` interface in [packages/jest-reporters/src/types.ts](https://github.com/facebook/jest/blob/master/packages/jest-reporters/src/types.ts) +For the full list of methods and argument types see `Reporter` interface in [packages/jest-reporters/src/types.ts](https://github.com/facebook/jest/blob/main/packages/jest-reporters/src/types.ts) ### `resetMocks` \[boolean] @@ -1067,7 +1067,7 @@ Pretty foo: Object { To make a dependency explicit instead of implicit, you can call [`expect.addSnapshotSerializer`](ExpectAPI.md#expectaddsnapshotserializerserializer) to add a module for an individual test file instead of adding its path to `snapshotSerializers` in Jest configuration. -More about serializers API can be found [here](https://github.com/facebook/jest/tree/master/packages/pretty-format/README.md#serialize). +More about serializers API can be found [here](https://github.com/facebook/jest/tree/main/packages/pretty-format/README.md#serialize). ### `testEnvironment` \[string] @@ -1090,7 +1090,7 @@ test('use jsdom in this test file', () => { You can create your own module that will be used for setting up the test environment. The module must export a class with `setup`, `teardown` and `getVmContext` methods. You can also pass variables from this module to your test suites by assigning them to `this.global` object – this will make them available in your test suites as global variables. -The class may optionally expose an asynchronous `handleTestEvent` method to bind to events fired by [`jest-circus`](https://github.com/facebook/jest/tree/master/packages/jest-circus). Normally, `jest-circus` test runner would pause until a promise returned from `handleTestEvent` gets fulfilled, **except for the next events**: `start_describe_definition`, `finish_describe_definition`, `add_hook`, `add_test` or `error` (for the up-to-date list you can look at [SyncEvent type in the types definitions](https://github.com/facebook/jest/tree/master/packages/jest-types/src/Circus.ts)). That is caused by backward compatibility reasons and `process.on('unhandledRejection', callback)` signature, but that usually should not be a problem for most of the use cases. +The class may optionally expose an asynchronous `handleTestEvent` method to bind to events fired by [`jest-circus`](https://github.com/facebook/jest/tree/main/packages/jest-circus). Normally, `jest-circus` test runner would pause until a promise returned from `handleTestEvent` gets fulfilled, **except for the next events**: `start_describe_definition`, `finish_describe_definition`, `add_hook`, `add_test` or `error` (for the up-to-date list you can look at [SyncEvent type in the types definitions](https://github.com/facebook/jest/tree/main/packages/jest-types/src/Circus.ts)). That is caused by backward compatibility reasons and `process.on('unhandledRejection', callback)` signature, but that usually should not be a problem for most of the use cases. Any docblock pragmas in test files will be passed to the environment constructor and can be used for per-test configuration. If the pragma does not have a value, it will be present in the object with its value set to an empty string. If the pragma is not present, it will not be present in the object. @@ -1285,7 +1285,7 @@ function testRunner( ): Promise; ``` -An example of such function can be found in our default [jasmine2 test runner package](https://github.com/facebook/jest/blob/master/packages/jest-jasmine2/src/index.ts). +An example of such function can be found in our default [jasmine2 test runner package](https://github.com/facebook/jest/blob/main/packages/jest-jasmine2/src/index.ts). ### `testSequencer` \[string] @@ -1345,7 +1345,7 @@ If the value is `legacy`, the old implementation will be used as implementation Default: `{"\\.[jt]sx?$": "babel-jest"}` -A map from regular expressions to paths to transformers. A transformer is a module that provides a synchronous function for transforming source files. For example, if you wanted to be able to use a new language feature in your modules or tests that aren't yet supported by node, you might plug in one of many compilers that compile a future version of JavaScript to a current one. Example: see the [examples/typescript](https://github.com/facebook/jest/blob/master/examples/typescript/package.json#L16) example or the [webpack tutorial](Webpack.md). +A map from regular expressions to paths to transformers. A transformer is a module that provides a synchronous function for transforming source files. For example, if you wanted to be able to use a new language feature in your modules or tests that aren't yet supported by node, you might plug in one of many compilers that compile a future version of JavaScript to a current one. Example: see the [examples/typescript](https://github.com/facebook/jest/blob/main/examples/typescript/package.json#L16) example or the [webpack tutorial](Webpack.md). Examples of such compilers include: @@ -1357,7 +1357,7 @@ You can pass configuration to a transformer like `{filePattern: ['path-to-transf _Note: a transformer is only run once per file unless the file has changed. During the development of a transformer it can be useful to run Jest with `--no-cache` to frequently [delete Jest's cache](Troubleshooting.md#caching-issues)._ -_Note: when adding additional code transformers, this will overwrite the default config and `babel-jest` is no longer automatically loaded. If you want to use it to compile JavaScript or Typescript, it has to be explicitly defined by adding `{"\\.[jt]sx?$": "babel-jest"}` to the transform property. See [babel-jest plugin](https://github.com/facebook/jest/tree/master/packages/babel-jest#setup)_ +_Note: when adding additional code transformers, this will overwrite the default config and `babel-jest` is no longer automatically loaded. If you want to use it to compile JavaScript or Typescript, it has to be explicitly defined by adding `{"\\.[jt]sx?$": "babel-jest"}` to the transform property. See [babel-jest plugin](https://github.com/facebook/jest/tree/main/packages/babel-jest#setup)_ A transformer must be an object with at least a `process` function, and it's also recommended to include a `getCacheKey` function. If your transformer is written in ESM you should have a default export with that object. diff --git a/docs/ExpectAPI.md b/docs/ExpectAPI.md index 43a39820e975..eddf1bec562e 100644 --- a/docs/ExpectAPI.md +++ b/docs/ExpectAPI.md @@ -151,7 +151,7 @@ A boolean to let you know this matcher was called with an `expand` option. When #### `this.utils` -There are a number of helpful tools exposed on `this.utils` primarily consisting of the exports from [`jest-matcher-utils`](https://github.com/facebook/jest/tree/master/packages/jest-matcher-utils). +There are a number of helpful tools exposed on `this.utils` primarily consisting of the exports from [`jest-matcher-utils`](https://github.com/facebook/jest/tree/main/packages/jest-matcher-utils). The most useful ones are `matcherHint`, `printExpected` and `printReceived` to format the error messages nicely. For example, take a look at the implementation for the `toBe` matcher: diff --git a/docs/JestObjectAPI.md b/docs/JestObjectAPI.md index 1e31360b4985..01b177bc598f 100644 --- a/docs/JestObjectAPI.md +++ b/docs/JestObjectAPI.md @@ -672,7 +672,7 @@ jest.setTimeout(1000); // 1 second ### `jest.retryTimes()` -Runs failed tests n-times until they pass or until the max number of retries is exhausted. This only works with the default [jest-circus](https://github.com/facebook/jest/tree/master/packages/jest-circus) runner! +Runs failed tests n-times until they pass or until the max number of retries is exhausted. This only works with the default [jest-circus](https://github.com/facebook/jest/tree/main/packages/jest-circus) runner! Example in a test: diff --git a/docs/JestPlatform.md b/docs/JestPlatform.md index cfadad5dced2..2273524221cd 100644 --- a/docs/JestPlatform.md +++ b/docs/JestPlatform.md @@ -23,7 +23,7 @@ getChangedFilesForRoots(['./'], { }).then(result => console.log(result.changedFiles)); ``` -You can read more about `jest-changed-files` in the [readme file](https://github.com/facebook/jest/blob/master/packages/jest-changed-files/README.md). +You can read more about `jest-changed-files` in the [readme file](https://github.com/facebook/jest/blob/main/packages/jest-changed-files/README.md). ## jest-diff @@ -68,7 +68,7 @@ const parsed = parseWithComments(code); console.log(parsed); ``` -You can read more about `jest-docblock` in the [readme file](https://github.com/facebook/jest/blob/master/packages/jest-docblock/README.md). +You can read more about `jest-docblock` in the [readme file](https://github.com/facebook/jest/blob/main/packages/jest-docblock/README.md). ## jest-get-type @@ -115,7 +115,7 @@ const result = validate(configByUser, { console.log(result); ``` -You can read more about `jest-validate` in the [readme file](https://github.com/facebook/jest/blob/master/packages/jest-validate/README.md). +You can read more about `jest-validate` in the [readme file](https://github.com/facebook/jest/blob/main/packages/jest-validate/README.md). ## jest-worker @@ -151,7 +151,7 @@ async function main() { main(); ``` -You can read more about `jest-worker` in the [readme file](https://github.com/facebook/jest/blob/master/packages/jest-worker/README.md). +You can read more about `jest-worker` in the [readme file](https://github.com/facebook/jest/blob/main/packages/jest-worker/README.md). ## pretty-format @@ -171,4 +171,4 @@ val.array = [-0, Infinity, NaN]; console.log(prettyFormat(val)); ``` -You can read more about `pretty-format` in the [readme file](https://github.com/facebook/jest/blob/master/packages/pretty-format/README.md). +You can read more about `pretty-format` in the [readme file](https://github.com/facebook/jest/blob/main/packages/pretty-format/README.md). diff --git a/docs/ManualMocks.md b/docs/ManualMocks.md index 4732d3d10cd4..d481a5712e49 100644 --- a/docs/ManualMocks.md +++ b/docs/ManualMocks.md @@ -127,7 +127,7 @@ The example mock shown here uses [`jest.createMockFromModule`](JestObjectAPI.md# 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)`](JestObjectAPI.md#jestrequireactualmodulename) 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). +The code for this example is available at [examples/manual-mocks](https://github.com/facebook/jest/tree/main/examples/manual-mocks). ## Using with ES module imports diff --git a/docs/MockFunctionAPI.md b/docs/MockFunctionAPI.md index fb2672b08fa6..3cc228fd7880 100644 --- a/docs/MockFunctionAPI.md +++ b/docs/MockFunctionAPI.md @@ -327,7 +327,7 @@ If you are using [Create React App](https://create-react-app.dev) then the [Type Otherwise, please see our [Getting Started](GettingStarted.md#using-typescript) guide for to get setup with TypeScript. -You can see an example of using Jest with TypeScript in our [GitHub repository](https://github.com/facebook/jest/tree/master/examples/typescript). +You can see an example of using Jest with TypeScript in our [GitHub repository](https://github.com/facebook/jest/tree/main/examples/typescript). ### `jest.MockedFunction` diff --git a/docs/MoreResources.md b/docs/MoreResources.md index eae5e5120b9f..e4509d53281f 100644 --- a/docs/MoreResources.md +++ b/docs/MoreResources.md @@ -15,7 +15,7 @@ By now you should have a good idea of how Jest can help you test your applicatio ## Learn by example -You will find a number of example test cases in the [`examples`](https://github.com/facebook/jest/tree/master/examples) folder on GitHub. You can also learn from the excellent tests used by the [React](https://github.com/facebook/react/tree/master/packages/react/src/__tests__), [Relay](https://github.com/facebook/relay/tree/master/packages/react-relay/__tests__), and [React Native](https://github.com/facebook/react-native/tree/master/Libraries/Animated/src/__tests__) projects. +You will find a number of example test cases in the [`examples`](https://github.com/facebook/jest/tree/main/examples) folder on GitHub. You can also learn from the excellent tests used by the [React](https://github.com/facebook/react/tree/main/packages/react/src/__tests__), [Relay](https://github.com/facebook/relay/tree/main/packages/react-relay/__tests__), and [React Native](https://github.com/facebook/react-native/tree/main/Libraries/Animated/src/__tests__) projects. ## Join the community diff --git a/docs/SnapshotTesting.md b/docs/SnapshotTesting.md index 1d7947fc7f75..3a8e79ed9788 100644 --- a/docs/SnapshotTesting.md +++ b/docs/SnapshotTesting.md @@ -9,7 +9,7 @@ A typical snapshot test case renders a UI component, takes a snapshot, then comp ## Snapshot Testing with Jest -A similar approach can be taken when it comes to testing your React components. Instead of rendering the graphical UI, which would require building the entire app, you can use a test renderer to quickly generate a serializable value for your React tree. Consider this [example test](https://github.com/facebook/jest/blob/master/examples/snapshot/__tests__/link.react.test.js) for a [Link component](https://github.com/facebook/jest/blob/master/examples/snapshot/Link.react.js): +A similar approach can be taken when it comes to testing your React components. Instead of rendering the graphical UI, which would require building the entire app, you can use a test renderer to quickly generate a serializable value for your React tree. Consider this [example test](https://github.com/facebook/jest/blob/main/examples/snapshot/__tests__/link.react.test.js) for a [Link component](https://github.com/facebook/jest/blob/main/examples/snapshot/Link.react.js): ```tsx import React from 'react'; @@ -24,7 +24,7 @@ it('renders correctly', () => { }); ``` -The first time this test is run, Jest creates a [snapshot file](https://github.com/facebook/jest/blob/master/examples/snapshot/__tests__/__snapshots__/link.react.test.js.snap) that looks like this: +The first time this test is run, Jest creates a [snapshot file](https://github.com/facebook/jest/blob/main/examples/snapshot/__tests__/__snapshots__/link.react.test.js.snap) that looks like this: ```javascript exports[`renders correctly 1`] = ` @@ -39,7 +39,7 @@ exports[`renders correctly 1`] = ` `; ``` -The snapshot artifact should be committed alongside code changes, and reviewed as part of your code review process. Jest uses [pretty-format](https://github.com/facebook/jest/tree/master/packages/pretty-format) to make snapshots human-readable during code review. On subsequent test runs, Jest will compare the rendered output with the previous snapshot. If they match, the test will pass. If they don't match, either the test runner found a bug in your code (in the `` component in this case) that should be fixed, or the implementation has changed and the snapshot needs to be updated. +The snapshot artifact should be committed alongside code changes, and reviewed as part of your code review process. Jest uses [pretty-format](https://github.com/facebook/jest/tree/main/packages/pretty-format) to make snapshots human-readable during code review. On subsequent test runs, Jest will compare the rendered output with the previous snapshot. If they match, the test will pass. If they don't match, either the test runner found a bug in your code (in the `` component in this case) that should be fixed, or the implementation has changed and the snapshot needs to be updated. > Note: The snapshot is directly scoped to the data you render – in our example the `` component with `page` prop passed to it. This implies that even if any other file has missing props (Say, `App.js`) in the `` component, it will still pass the test as the test doesn't know the usage of `` component and it's scoped only to the `Link.react.js`. Also, Rendering the same component with different props in other snapshot tests will not affect the first one, as the tests don't know about each other. @@ -77,7 +77,7 @@ Go ahead and accept the changes by running the above command. You may also use t If you'd like to limit which snapshot test cases get re-generated, you can pass an additional `--testNamePattern` flag to re-record snapshots only for those tests that match the pattern. -You can try out this functionality by cloning the [snapshot example](https://github.com/facebook/jest/tree/master/examples/snapshot), modifying the `Link` component, and running Jest. +You can try out this functionality by cloning the [snapshot example](https://github.com/facebook/jest/tree/main/examples/snapshot), modifying the `Link` component, and running Jest. ### Interactive Snapshot Mode @@ -219,7 +219,7 @@ Commit snapshots and review them as part of your regular code review process. Th Ensure that your snapshots are readable by keeping them focused, short, and by using tools that enforce these stylistic conventions. -As mentioned previously, Jest uses [`pretty-format`](https://yarnpkg.com/en/package/pretty-format) to make snapshots human-readable, but you may find it useful to introduce additional tools, like [`eslint-plugin-jest`](https://yarnpkg.com/en/package/eslint-plugin-jest) with its [`no-large-snapshots`](https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules/no-large-snapshots.md) option, or [`snapshot-diff`](https://yarnpkg.com/en/package/snapshot-diff) with its component snapshot comparison feature, to promote committing short, focused assertions. +As mentioned previously, Jest uses [`pretty-format`](https://yarnpkg.com/en/package/pretty-format) to make snapshots human-readable, but you may find it useful to introduce additional tools, like [`eslint-plugin-jest`](https://yarnpkg.com/en/package/eslint-plugin-jest) with its [`no-large-snapshots`](https://github.com/jest-community/eslint-plugin-jest/blob/main/docs/rules/no-large-snapshots.md) option, or [`snapshot-diff`](https://yarnpkg.com/en/package/snapshot-diff) with its component snapshot comparison feature, to promote committing short, focused assertions. The goal is to make it easy to review snapshots in pull requests, and fight against the habit of regenerating snapshots when test suites fail instead of examining the root causes of their failure. @@ -227,7 +227,7 @@ The goal is to make it easy to review snapshots in pull requests, and fight agai Your tests should be deterministic. Running the same tests multiple times on a component that has not changed should produce the same results every time. You're responsible for making sure your generated snapshots do not include platform specific or other non-deterministic data. -For example, if you have a [Clock](https://github.com/facebook/jest/blob/master/examples/snapshot/Clock.react.js) component that uses `Date.now()`, the snapshot generated from this component will be different every time the test case is run. In this case we can [mock the Date.now() method](MockFunctions.md) to return a consistent value every time the test is run: +For example, if you have a [Clock](https://github.com/facebook/jest/blob/main/examples/snapshot/Clock.react.js) component that uses `Date.now()`, the snapshot generated from this component will be different every time the test case is run. In this case we can [mock the Date.now() method](MockFunctions.md) to return a consistent value every time the test is run: ```js Date.now = jest.fn(() => 1482363367071); @@ -287,7 +287,7 @@ Yes, all snapshot files should be committed alongside the modules they are cover ### Does snapshot testing only work with React components? -[React](TutorialReact.md) and [React Native](TutorialReactNative.md) components are a good use case for snapshot testing. However, snapshots can capture any serializable value and should be used anytime the goal is testing whether the output is correct. The Jest repository contains many examples of testing the output of Jest itself, the output of Jest's assertion library as well as log messages from various parts of the Jest codebase. See an example of [snapshotting CLI output](https://github.com/facebook/jest/blob/master/e2e/__tests__/console.test.ts) in the Jest repo. +[React](TutorialReact.md) and [React Native](TutorialReactNative.md) components are a good use case for snapshot testing. However, snapshots can capture any serializable value and should be used anytime the goal is testing whether the output is correct. The Jest repository contains many examples of testing the output of Jest itself, the output of Jest's assertion library as well as log messages from various parts of the Jest codebase. See an example of [snapshotting CLI output](https://github.com/facebook/jest/blob/main/e2e/__tests__/console.test.ts) in the Jest repo. ### What's the difference between snapshot testing and visual regression testing? diff --git a/docs/TimerMocks.md b/docs/TimerMocks.md index 5170e399a977..43e07ca0201f 100644 --- a/docs/TimerMocks.md +++ b/docs/TimerMocks.md @@ -175,4 +175,4 @@ it('calls the callback after 1 second via advanceTimersByTime', () => { Lastly, it may occasionally be useful in some tests to be able to clear all of the pending timers. For this, we have `jest.clearAllTimers()`. -The code for this example is available at [examples/timer](https://github.com/facebook/jest/tree/master/examples/timer). +The code for this example is available at [examples/timer](https://github.com/facebook/jest/tree/main/examples/timer). diff --git a/docs/TutorialAsync.md b/docs/TutorialAsync.md index aea53809b0cf..f9418ad6651b 100644 --- a/docs/TutorialAsync.md +++ b/docs/TutorialAsync.md @@ -160,6 +160,6 @@ it('tests error with async/await and rejects', async () => { }); ``` -The code for this example is available at [examples/async](https://github.com/facebook/jest/tree/master/examples/async). +The code for this example is available at [examples/async](https://github.com/facebook/jest/tree/main/examples/async). If you'd like to test timers, like `setTimeout`, take a look at the [Timer mocks](TimerMocks.md) documentation. diff --git a/docs/TutorialReact.md b/docs/TutorialReact.md index 838918fa8e4a..7cce1e08cf10 100644 --- a/docs/TutorialReact.md +++ b/docs/TutorialReact.md @@ -162,7 +162,7 @@ exports[`Link changes the class when hovered 3`] = ` The next time you run the tests, the rendered output will be compared to the previously created snapshot. The snapshot should be committed along with code changes. When a snapshot test fails, you need to inspect whether it is an intended or unintended change. If the change is expected you can invoke Jest with `jest -u` to overwrite the existing snapshot. -The code for this example is available at [examples/snapshot](https://github.com/facebook/jest/tree/master/examples/snapshot). +The code for this example is available at [examples/snapshot](https://github.com/facebook/jest/tree/main/examples/snapshot). #### Snapshot Testing with Mocks, Enzyme and React 16 @@ -253,7 +253,7 @@ it('CheckboxWithLabel changes the text after click', () => { }); ``` -The code for this example is available at [examples/react-testing-library](https://github.com/facebook/jest/tree/master/examples/react-testing-library). +The code for this example is available at [examples/react-testing-library](https://github.com/facebook/jest/tree/main/examples/react-testing-library). #### Enzyme @@ -280,7 +280,7 @@ test('CheckboxWithLabel changes the text after click', () => { }); ``` -The code for this example is available at [examples/enzyme](https://github.com/facebook/jest/tree/master/examples/enzyme). +The code for this example is available at [examples/enzyme](https://github.com/facebook/jest/tree/main/examples/enzyme). ### Custom transformers diff --git a/docs/TutorialReactNative.md b/docs/TutorialReactNative.md index bba83bf1c291..3bbe76e5793f 100644 --- a/docs/TutorialReactNative.md +++ b/docs/TutorialReactNative.md @@ -124,7 +124,7 @@ exports[`Intro renders correctly 1`] = ` The next time you run the tests, the rendered output will be compared to the previously created snapshot. The snapshot should be committed along with code changes. When a snapshot test fails, you need to inspect whether it is an intended or unintended change. If the change is expected you can invoke Jest with `jest -u` to overwrite the existing snapshot. -The code for this example is available at [examples/react-native](https://github.com/facebook/jest/tree/master/examples/react-native). +The code for this example is available at [examples/react-native](https://github.com/facebook/jest/tree/main/examples/react-native). ## Preset configuration diff --git a/docs/TutorialjQuery.md b/docs/TutorialjQuery.md index fea33d6eb703..7532f285918f 100644 --- a/docs/TutorialjQuery.md +++ b/docs/TutorialjQuery.md @@ -65,4 +65,4 @@ The function being tested adds an event listener on the `#button` DOM element, s We are mocking `fetchCurrentUser.js` so that our test doesn't make a real network request but instead resolves to mock data locally. This ensures that our test can complete in milliseconds rather than seconds and guarantees a fast unit test iteration speed. -The code for this example is available at [examples/jquery](https://github.com/facebook/jest/tree/master/examples/jquery). +The code for this example is available at [examples/jquery](https://github.com/facebook/jest/tree/main/examples/jquery). diff --git a/packages/babel-plugin-jest-hoist/README.md b/packages/babel-plugin-jest-hoist/README.md index 15c1b181d7d6..1a90bbe8b165 100644 --- a/packages/babel-plugin-jest-hoist/README.md +++ b/packages/babel-plugin-jest-hoist/README.md @@ -1,6 +1,6 @@ # babel-plugin-jest-hoist -Babel plugin to hoist `jest.disableAutomock`, `jest.enableAutomock`, `jest.unmock`, `jest.mock`, calls above `import` statements. This plugin is automatically included when using [babel-jest](https://github.com/facebook/jest/tree/master/packages/babel-jest). +Babel plugin to hoist `jest.disableAutomock`, `jest.enableAutomock`, `jest.unmock`, `jest.mock`, calls above `import` statements. This plugin is automatically included when using [babel-jest](https://github.com/facebook/jest/tree/main/packages/babel-jest). ## Installation diff --git a/packages/babel-preset-jest/README.md b/packages/babel-preset-jest/README.md index b0f085f6abde..4457c086cece 100644 --- a/packages/babel-preset-jest/README.md +++ b/packages/babel-preset-jest/README.md @@ -1,6 +1,6 @@ # babel-preset-jest -> Babel preset for all Jest plugins. This preset is automatically included when using [babel-jest](https://github.com/facebook/jest/tree/master/packages/babel-jest). +> Babel preset for all Jest plugins. This preset is automatically included when using [babel-jest](https://github.com/facebook/jest/tree/main/packages/babel-jest). ## Install diff --git a/packages/jest-circus/README.md b/packages/jest-circus/README.md index 10365889006b..67305ed4a04a 100644 --- a/packages/jest-circus/README.md +++ b/packages/jest-circus/README.md @@ -1,4 +1,4 @@ -[type-definitions]: https://github.com/facebook/jest/blob/master/packages/jest-types/src/Circus.ts +[type-definitions]: https://github.com/facebook/jest/blob/main/packages/jest-types/src/Circus.ts

diff --git a/packages/jest-each/README.md b/packages/jest-each/README.md index 43dc11a4e5f2..da3b2adb9e4a 100644 --- a/packages/jest-each/README.md +++ b/packages/jest-each/README.md @@ -5,7 +5,7 @@
-[![version](https://img.shields.io/npm/v/jest-each.svg?style=flat-square)](https://www.npmjs.com/package/jest-each) [![downloads](https://img.shields.io/npm/dm/jest-each.svg?style=flat-square)](http://npm-stat.com/charts.html?package=jest-each&from=2017-03-21) [![MIT License](https://img.shields.io/npm/l/jest-each.svg?style=flat-square)](https://github.com/facebook/jest/blob/master/LICENSE) +[![version](https://img.shields.io/npm/v/jest-each.svg?style=flat-square)](https://www.npmjs.com/package/jest-each) [![downloads](https://img.shields.io/npm/dm/jest-each.svg?style=flat-square)](http://npm-stat.com/charts.html?package=jest-each&from=2017-03-21) [![MIT License](https://img.shields.io/npm/l/jest-each.svg?style=flat-square)](https://github.com/facebook/jest/blob/main/LICENSE) A parameterised testing library for [Jest](https://jestjs.io/) inspired by [mocha-each](https://github.com/ryym/mocha-each). diff --git a/packages/pretty-format/src/index.ts b/packages/pretty-format/src/index.ts index b497aa324df7..751c437a7ff4 100644 --- a/packages/pretty-format/src/index.ts +++ b/packages/pretty-format/src/index.ts @@ -181,7 +181,7 @@ function printBasicValue( } if (toStringed === '[object RegExp]') { if (escapeRegex) { - // https://github.com/benjamingr/RegExp.escape/blob/master/polyfill.js + // https://github.com/benjamingr/RegExp.escape/blob/main/polyfill.js return regExpToString.call(val).replace(/[\\^$*+?.()|[\]{}]/g, '\\$&'); } return regExpToString.call(val); diff --git a/website/README.md b/website/README.md index 348415cfe1b6..3e1c69680055 100644 --- a/website/README.md +++ b/website/README.md @@ -30,7 +30,7 @@ Note, you can also use `yarn workspace jest-website start` from the root of the ## Publish the website -The site is deployed on each PR merged to master by Netlify: +The site is deployed on each PR merged to main by Netlify: - Netlify site: https://app.netlify.com/sites/jestjs - Netlify url: https://jestjs.netlify.app diff --git a/website/blog/2016-03-11-javascript-unit-testing-performance.md b/website/blog/2016-03-11-javascript-unit-testing-performance.md index 719a50817506..b59de046ad25 100644 --- a/website/blog/2016-03-11-javascript-unit-testing-performance.md +++ b/website/blog/2016-03-11-javascript-unit-testing-performance.md @@ -70,7 +70,7 @@ describe('sum', () => { }); ``` -We built a babel transform called [inline-requires](https://github.com/facebook/fbjs/blob/master/packages/babel-preset-fbjs/plugins/inline-requires.js) that removes top-level require statements and inlines them in code. For example, the line `const sum = require('sum');` will be removed from code, but every use of `sum` in the file will be replaced by `require('sum')`. With this transform we can write tests just like you'd expect in Jasmine and the code gets transformed into this: +We built a babel transform called [inline-requires](https://github.com/facebook/fbjs/blob/main/packages/babel-preset-fbjs/plugins/inline-requires.js) that removes top-level require statements and inlines them in code. For example, the line `const sum = require('sum');` will be removed from code, but every use of `sum` in the file will be replaced by `require('sum')`. With this transform we can write tests just like you'd expect in Jasmine and the code gets transformed into this: ```js describe('sum', () => { diff --git a/website/blog/2016-04-12-jest-11.md b/website/blog/2016-04-12-jest-11.md index e774c1bbccf9..2991188f481b 100644 --- a/website/blog/2016-04-12-jest-11.md +++ b/website/blog/2016-04-12-jest-11.md @@ -13,7 +13,7 @@ If you are using Jest 0.9 or Jest 0.10 the upgrade should be seamless. All chang #### Babel Integration and Simplified Setup -`babel-jest` was adopted within the newly modularized Jest [repository](https://github.com/facebook/jest/tree/master/packages) and it is now seamlessly integrated into Jest. If you are upgrading from an older version of Jest or are looking to adopt Jest, we recommend reading the [Getting Started guide](/docs/getting-started). +`babel-jest` was adopted within the newly modularized Jest [repository](https://github.com/facebook/jest/tree/main/packages) and it is now seamlessly integrated into Jest. If you are upgrading from an older version of Jest or are looking to adopt Jest, we recommend reading the [Getting Started guide](/docs/getting-started). @@ -86,7 +86,7 @@ We have also made many updates around Jasmine. The failure messages for custom m The `jest --watch` command has been rewritten and improved. By default it now only runs tests related to changed files. If you want to run all tests on every change, you can run `jest --watch=all`. The verbose logger output has also been improved and we've added more helpful warnings and error messages. We added a [`testEnvironment`](/docs/api#testenvironment-string) configuration option to customize the test environment. For example, when building a node service, a special `node` environment instead of `jsdom` can be used. Finally, the website and all documentation have been completely rewritten. -All changes from the past few months can be found in the [CHANGELOG](https://github.com/facebook/jest/blob/master/CHANGELOG.md). +All changes from the past few months can be found in the [CHANGELOG](https://github.com/facebook/jest/blob/main/CHANGELOG.md). ### Contributions And Jest's future diff --git a/website/blog/2016-06-22-jest-13.md b/website/blog/2016-06-22-jest-13.md index 3bd61f1664a8..855c2f927328 100644 --- a/website/blog/2016-06-22-jest-13.md +++ b/website/blog/2016-06-22-jest-13.md @@ -11,7 +11,7 @@ The Flow project has evolved a lot within Facebook and has been successfully ado -With the help of [lerna](https://github.com/lerna/lerna), we continued to modularize the Jest project. With just a small [update to the configuration](https://github.com/lerna/lerna#lernajson), Flow and lerna now get along well with each other. Splitting up Jest into packages helped us rethink module boundaries and enabled us to ship useful [packages](https://github.com/facebook/jest/tree/master/packages) standalone: The `jest-runtime` and `jest-repl` cli tools now allow you to run scripts in a sandboxed Jest environment, enabling you to run and debug your app from the command line. This is especially helpful for projects that use Facebook's `@providesModule` module convention. To get started, just install `jest-repl` and run it in the same folder you normally run your tests in! We also published a `jest-changed-files` package that finds changed files in version control for either git or hg, a common thing in developer tools. +With the help of [lerna](https://github.com/lerna/lerna), we continued to modularize the Jest project. With just a small [update to the configuration](https://github.com/lerna/lerna#lernajson), Flow and lerna now get along well with each other. Splitting up Jest into packages helped us rethink module boundaries and enabled us to ship useful [packages](https://github.com/facebook/jest/tree/main/packages) standalone: The `jest-runtime` and `jest-repl` cli tools now allow you to run scripts in a sandboxed Jest environment, enabling you to run and debug your app from the command line. This is especially helpful for projects that use Facebook's `@providesModule` module convention. To get started, just install `jest-repl` and run it in the same folder you normally run your tests in! We also published a `jest-changed-files` package that finds changed files in version control for either git or hg, a common thing in developer tools. ## New and improved features diff --git a/website/blog/2016-07-27-jest-14.md b/website/blog/2016-07-27-jest-14.md index 971793cc5212..0ab082518276 100644 --- a/website/blog/2016-07-27-jest-14.md +++ b/website/blog/2016-07-27-jest-14.md @@ -11,7 +11,7 @@ One of the big open questions was how to write React tests efficiently. There ar -Together with the React team we created a new test renderer for React and added snapshot testing to Jest. Consider this [example test](https://github.com/facebook/jest/blob/master/examples/snapshot/__tests__/Link.react-test.js) for a simple [Link component](https://github.com/facebook/jest/blob/master/examples/snapshot/Link.react.js): +Together with the React team we created a new test renderer for React and added snapshot testing to Jest. Consider this [example test](https://github.com/facebook/jest/blob/main/examples/snapshot/__tests__/Link.react-test.js) for a simple [Link component](https://github.com/facebook/jest/blob/main/examples/snapshot/Link.react.js): ```javascript import renderer from 'react-test-renderer'; @@ -23,7 +23,7 @@ test('Link renders correctly', () => { }); ``` -The first time this test is run, Jest creates a [snapshot file](https://github.com/facebook/jest/blob/master/examples/snapshot/__tests__/__snapshots__/Link.react-test.js.snap) that looks like this: +The first time this test is run, Jest creates a [snapshot file](https://github.com/facebook/jest/blob/main/examples/snapshot/__tests__/__snapshots__/Link.react-test.js.snap) that looks like this: ```javascript exports[`Link renders correctly 1`] = ` @@ -43,7 +43,7 @@ If we change the address the Link component in our example is pointing to, Jest ![snapshot-testing](/img/blog/snapshot.png) -Now you know that you either need to accept the changes with `jest -u`, or fix the component if the changes were unintentional. To try out this functionality, please clone the [snapshot example](https://github.com/facebook/jest/tree/master/examples/snapshot), modify the Link component and run Jest. We updated the [React Tutorial](/docs/tutorial-react) with a new guide for snapshot testing. +Now you know that you either need to accept the changes with `jest -u`, or fix the component if the changes were unintentional. To try out this functionality, please clone the [snapshot example](https://github.com/facebook/jest/tree/main/examples/snapshot), modify the Link component and run Jest. We updated the [React Tutorial](/docs/tutorial-react) with a new guide for snapshot testing. This feature was built by [Ben Alpert](https://twitter.com/soprano) and [Cristian Carlesso](https://twitter.com/kentaromiura). @@ -60,7 +60,7 @@ You can start using Jest with react-native by running `yarn add --dev jest-react ``` - [Tutorial and setup guide](/docs/tutorial-react-native#content) -- [Example project](https://github.com/facebook/jest/tree/master/examples/react-native) +- [Example project](https://github.com/facebook/jest/tree/main/examples/react-native) - [Example pull request for _snowflake_](https://github.com/bartonhammond/snowflake/pull/110), a popular react-native open source library. _Note: the preset currently only implements the minimal set of configuration necessary to get started with React Native testing. We are hoping for community contributions to improve this project. Please try it and file [issues](https://github.com/facebook/jest/issues) or send pull requests!_ @@ -75,7 +75,7 @@ While this was the solution we wanted for the web, we also found many problems w - **Fast iteration speed:** Engineers want to get results in less than a second rather than waiting for minutes or even hours. If tests don't run quickly like in most end-to-end frameworks, engineers don't run them at all or don't bother writing them in the first place. - **Debugging:** It's easy to step into the code of an integration test in JS instead of trying to recreate the screenshot test scenario and debugging what happened in the visual diff. -Because we believe snapshot testing can be useful beyond Jest we split the feature into a [jest-snapshot](https://github.com/facebook/jest/tree/master/packages/jest-snapshot) package. We are happy to work with the community to make it more generic so it can be integrated with other test runners and share concepts and infrastructure with each other. +Because we believe snapshot testing can be useful beyond Jest we split the feature into a [jest-snapshot](https://github.com/facebook/jest/tree/main/packages/jest-snapshot) package. We are happy to work with the community to make it more generic so it can be integrated with other test runners and share concepts and infrastructure with each other. Finally, here is a quote of a Facebook engineer describing how snapshot testing changed his unit testing experience: diff --git a/website/blog/2016-10-03-jest-16.md b/website/blog/2016-10-03-jest-16.md index 59902acc031a..3e718ab2a7d4 100644 --- a/website/blog/2016-10-03-jest-16.md +++ b/website/blog/2016-10-03-jest-16.md @@ -76,4 +76,4 @@ Other highlights about snapshot testing: If you are using other test runners, Kenneth Skovhus built an awesome [jest-codemods](https://github.com/skovhus/jest-codemods) library that will automate the conversion for you. Codemods are awesome: they'll allow you to quickly evaluate whether Jest will work for you. Give it a try! -The full [changelog can be found on GitHub](https://github.com/facebook/jest/blob/master/CHANGELOG.md#jest-1600). Jest 16 was a true JavaScript community effort and the project now has more than 220 contributors. We thank each and every one of you for your help to make this project great. +The full [changelog can be found on GitHub](https://github.com/facebook/jest/blob/main/CHANGELOG.md#jest-1600). Jest 16 was a true JavaScript community effort and the project now has more than 220 contributors. We thank each and every one of you for your help to make this project great. diff --git a/website/blog/2016-12-15-2016-in-jest.md b/website/blog/2016-12-15-2016-in-jest.md index 222633e4e24f..19942581ab08 100644 --- a/website/blog/2016-12-15-2016-in-jest.md +++ b/website/blog/2016-12-15-2016-in-jest.md @@ -5,13 +5,13 @@ authorURL: http://twitter.com/cpojer authorFBID: 100000023028168 --- -2016 was a big year for JavaScript testing with Jest. In the first six months of the year we rewrote Jest and built a solid foundation to significantly improve performance and the developer experience of testing JavaScript code. We flow-typed the entire codebase, built a ton of integration tests for Jest itself and adopted [lerna](https://lernajs.io/) to turn Jest from a framework into a [_Painless JavaScript Testing platform_](https://github.com/facebook/jest/tree/master/packages). +2016 was a big year for JavaScript testing with Jest. In the first six months of the year we rewrote Jest and built a solid foundation to significantly improve performance and the developer experience of testing JavaScript code. We flow-typed the entire codebase, built a ton of integration tests for Jest itself and adopted [lerna](https://lernajs.io/) to turn Jest from a framework into a [_Painless JavaScript Testing platform_](https://github.com/facebook/jest/tree/main/packages). -The newly created [react-test-renderer](https://yarnpkg.com/en/package/react-test-renderer) finally enabled testing of react-native components. Through the jest-react-native preset (now merged directly into react-native) Jest now works out of the box for any React project and comes pre-configured in [create-react-app](https://github.com/facebookincubator/create-react-app) and [react-native](https://github.com/facebook/react-native) projects. We integrated core pieces of Jest into [react-native's packager](https://github.com/facebook/react-native/tree/master/packager/react-packager/src) and the completely new snapshot testing feature has since been used outside of Jest: It was integrated with React Storybook as “[storyshots](https://github.com/storybooks/storyshots)” and is being adopted by other test runners like [ava](https://github.com/avajs/ava/pull/1113). +The newly created [react-test-renderer](https://yarnpkg.com/en/package/react-test-renderer) finally enabled testing of react-native components. Through the jest-react-native preset (now merged directly into react-native) Jest now works out of the box for any React project and comes pre-configured in [create-react-app](https://github.com/facebookincubator/create-react-app) and [react-native](https://github.com/facebook/react-native) projects. We integrated core pieces of Jest into [react-native's packager](https://github.com/facebook/react-native/tree/main/packager/react-packager/src) and the completely new snapshot testing feature has since been used outside of Jest: It was integrated with React Storybook as “[storyshots](https://github.com/storybooks/storyshots)” and is being adopted by other test runners like [ava](https://github.com/avajs/ava/pull/1113). -The [pretty-format](https://github.com/facebook/jest/tree/master/packages/pretty-format) project was rewritten with performance in mind to drive Jest's snapshot feature, was recently merged into Jest's monorepo and is also helpful in other [test runners](https://github.com/avajs/ava/pull/1154). Nowadays Jest is much more about collecting different ideas and solutions to testing than it is about one specific implementation of a test framework. +The [pretty-format](https://github.com/facebook/jest/tree/main/packages/pretty-format) project was rewritten with performance in mind to drive Jest's snapshot feature, was recently merged into Jest's monorepo and is also helpful in other [test runners](https://github.com/avajs/ava/pull/1154). Nowadays Jest is much more about collecting different ideas and solutions to testing than it is about one specific implementation of a test framework. I'd like to deeply thank all the people that have [contributed to Jest this year](https://github.com/facebook/jest/graphs/contributors?from=2016-01-01&to=2016-12-14&type=c), both from the open source community and at Facebook: Dmitrii Abramov, Cristian Carlesso, Dan Abramov, Daniel Lo Nigro, Maxim Derbin, Evan Scott, Forbes Lindesay, Keyan Zhang and 60 more people. We'd also like to welcome [Michał Pierzchała (@thymikee)](https://twitter.com/thymikee) as first official external contributor to Jest. He's been doing a great job managing the issues and PRs on the repo. If you'd like to start contributing to Jest, we have a bunch of [good first tasks](https://github.com/facebook/jest/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+bug%22) and we are always happy to help on our [discord channel](https://discord.gg/j6FKKQQrW9). @@ -53,7 +53,7 @@ Here is what happened in the community in the last two months: ## New features, changes and fixes in Jest 17 & 18 -Jest was initially created more than five years ago and as such an old framework it has accumulated some technical debt. This is why we tend to make breaking changes more often than may seem necessary: We believe it is important to incrementally reduce technical debt to ensure that Jest as a project stays maintainable long-term. We didn't announce Jest 17 in a blog post and if you haven't upgraded to it in the last month you may find the [changelog](https://github.com/facebook/jest/blob/master/CHANGELOG.md) useful. +Jest was initially created more than five years ago and as such an old framework it has accumulated some technical debt. This is why we tend to make breaking changes more often than may seem necessary: We believe it is important to incrementally reduce technical debt to ensure that Jest as a project stays maintainable long-term. We didn't announce Jest 17 in a blog post and if you haven't upgraded to it in the last month you may find the [changelog](https://github.com/facebook/jest/blob/main/CHANGELOG.md) useful. - **Breaking:** Removed `pit` in favor of `it` or `test` and `mockImpl` in favor of `jest.fn()` or `mockImplementation` . - **Breaking:** Renamed `--jsonOutputFile` to `--outputFile`. diff --git a/website/blog/2017-02-21-jest-19-immersive-watch-mode-test-platform-improvements.md b/website/blog/2017-02-21-jest-19-immersive-watch-mode-test-platform-improvements.md index f2cda6141219..b35b32016f50 100644 --- a/website/blog/2017-02-21-jest-19-immersive-watch-mode-test-platform-improvements.md +++ b/website/blog/2017-02-21-jest-19-immersive-watch-mode-test-platform-improvements.md @@ -83,17 +83,17 @@ We now also error on invalid CLI arguments instead of ignoring them. But we've g We're close to almost full feature parity with the `expect` npm package. [Michael Jackson](https://twitter.com/mjackson), the author of the package, agreed to [donate](https://github.com/facebook/jest/issues/1679) it to the Jest project, which means that `jest-matchers` will be renamed to `expect`. Since our version of `expect` is not intended to be fully compatible, [Christopher Chedeau](https://twitter.com/Vjeux) is working on a codemod to make the transition painless. Christopher also worked on a number of improvements to `jest-matchers` which enables it to be used outside of Jest and even [works inside browsers](https://github.com/facebook/jest/pull/2795). -## [eslint-plugin-jest](https://github.com/facebook/jest/tree/master/packages/eslint-plugin-jest) – our very own ESLint plugin +## [eslint-plugin-jest](https://github.com/facebook/jest/tree/main/packages/eslint-plugin-jest) – our very own ESLint plugin Thanks to [Jonathan Kim](https://twitter.com/jonnykim) Jest finally has its own official ESLint plugin. It exposes three rules: -- [no-disabled-tests](https://github.com/facebook/jest/blob/master/packages/eslint-plugin-jest/docs/rules/no-disabled-tests.md) - this rule prevents you from accidentally committing disabled tests. -- [no-focused-tests](https://github.com/facebook/jest/blob/master/packages/eslint-plugin-jest/docs/rules/no-focused-tests.md) - this rule prevents you from committing focused tests which would disable all other tests in the same suite. -- [no-identical-title](https://github.com/facebook/jest/blob/master/packages/eslint-plugin-jest/docs/rules/no-identical-title.md) - disallows identical titles in test names. +- [no-disabled-tests](https://github.com/facebook/jest/blob/main/packages/eslint-plugin-jest/docs/rules/no-disabled-tests.md) - this rule prevents you from accidentally committing disabled tests. +- [no-focused-tests](https://github.com/facebook/jest/blob/main/packages/eslint-plugin-jest/docs/rules/no-focused-tests.md) - this rule prevents you from committing focused tests which would disable all other tests in the same suite. +- [no-identical-title](https://github.com/facebook/jest/blob/main/packages/eslint-plugin-jest/docs/rules/no-identical-title.md) - disallows identical titles in test names. You can install it using `npm install --save-dev eslint-plugin-jest` or `yarn add --dev eslint eslint-plugin-jest` and it can be enabled by adding `{"plugins": ["jest"]}` to your eslint configuration. -## New public package: [jest-validate](https://github.com/facebook/jest/tree/master/packages/jest-validate) +## New public package: [jest-validate](https://github.com/facebook/jest/tree/main/packages/jest-validate) While we refactored the validation and normalization code for Jest's configuration, we were so happy with the new error messaging that we extracted it to its own module to share it with everyone. With Jest 19 we welcome `jest-validate` to our self-sustained packages family. @@ -101,7 +101,7 @@ While we refactored the validation and normalization code for Jest's configurati ![validate](/img/blog/19-validate.png) -We're happy to announce that `jest-validate` is validating config options of [prettier](https://github.com/jlongster/prettier) since [v0.12](https://github.com/jlongster/prettier/blob/master/CHANGELOG.md#0120). Feel free to add it to your project, try it, send us feedback and improve it by making pull requests on GitHub. +We're happy to announce that `jest-validate` is validating config options of [prettier](https://github.com/jlongster/prettier) since [v0.12](https://github.com/jlongster/prettier/blob/main/CHANGELOG.md#0120). Feel free to add it to your project, try it, send us feedback and improve it by making pull requests on GitHub. ## Improved asymmetric matchers @@ -139,8 +139,8 @@ The homepage was completely redesigned to be more descriptive of what Jest is ab - Jest is now part of [react-boilerplate](https://twitter.com/mxstbr/status/820326656439177217). - Read about the [hidden powers of Jest's matchers](https://medium.com/@boriscoder/the-hidden-power-of-jest-matchers-f3d86d8101b0#.pn10z1pzx). -Finally, we are happy to announce that the [ava](https://github.com/avajs/ava) test runner has adopted parts of the Jest platform and is now shipping with basic [snapshot support](https://github.com/avajs/ava#snapshot-testing) and is using [pretty-format](https://github.com/facebook/jest/tree/master/packages/pretty-format). Consolidating test infrastructure makes it easier to learn how to test applications and enables us to share best practices. We are looking forward to see what we can learn from existing test libraries in the future. +Finally, we are happy to announce that the [ava](https://github.com/avajs/ava) test runner has adopted parts of the Jest platform and is now shipping with basic [snapshot support](https://github.com/avajs/ava#snapshot-testing) and is using [pretty-format](https://github.com/facebook/jest/tree/main/packages/pretty-format). Consolidating test infrastructure makes it easier to learn how to test applications and enables us to share best practices. We are looking forward to see what we can learn from existing test libraries in the future. -The full [changelog can be found on GitHub](https://github.com/facebook/jest/blob/master/CHANGELOG.md#jest-1900). Jest 19 was a true JavaScript community effort with [17 people who contributed](https://github.com/facebook/jest/graphs/contributors?from=2016-12-23&to=2017-02-21&type=c) to this release. We thank each and every one of you for your help to make this project great. +The full [changelog can be found on GitHub](https://github.com/facebook/jest/blob/main/CHANGELOG.md#jest-1900). Jest 19 was a true JavaScript community effort with [17 people who contributed](https://github.com/facebook/jest/graphs/contributors?from=2016-12-23&to=2017-02-21&type=c) to this release. We thank each and every one of you for your help to make this project great. _This blog post was written by [Rogelio Guzman](https://twitter.com/rogeliog) and [Michał Pierzchała](https://twitter.com/thymikee)._ diff --git a/website/blog/2017-05-06-jest-20-delightful-testing-multi-project-runner.md b/website/blog/2017-05-06-jest-20-delightful-testing-multi-project-runner.md index bf14c34e6fb0..320a55dd8b55 100644 --- a/website/blog/2017-05-06-jest-20-delightful-testing-multi-project-runner.md +++ b/website/blog/2017-05-06-jest-20-delightful-testing-multi-project-runner.md @@ -78,7 +78,7 @@ As with every major release, we are making a number of breaking changes to make - **Translations:** We are now asking for your help to [translate the Jest documentation](https://crowdin.com/project/jest-v2) to make it easier for people to learn how to use Jest. - **Custom Reporters:** Jest now supports custom test reporters through the `reporters` configuration option. You can finally customize the output of Jest as well as integrate it with other tools by generating reports in formats such as XML. [See documentation](/docs/configuration#reporters-array-modulename-modulename-options). - **Codebase Health:** It was only possible iterate so quickly in Jest because we spent a significant amount of time on the health of the codebase. We were one of the early adopters of [prettier](https://github.com/prettier/prettier), we notably increased flow coverage, forked Jasmine to improve our test runner library and we rewrote and refactored significant portions of Jest itself to set up Jest for success in the future. -- **Bugfixes:** As always, we made plenty of bugfixes in Jest. The full changelog can be found in the [Jest repository](https://github.com/facebook/jest/blob/master/CHANGELOG.md#jest-2000). +- **Bugfixes:** As always, we made plenty of bugfixes in Jest. The full changelog can be found in the [Jest repository](https://github.com/facebook/jest/blob/main/CHANGELOG.md#jest-2000). ## Talks about Jest diff --git a/website/blog/2017-12-18-jest-22.md b/website/blog/2017-12-18-jest-22.md index 0f15c0c01d55..201d444f54fa 100644 --- a/website/blog/2017-12-18-jest-22.md +++ b/website/blog/2017-12-18-jest-22.md @@ -5,7 +5,7 @@ authorURL: https://github.com/SimenB authorFBID: 100003004880942 --- -Today we are announcing a new major version of Jest which refines almost all parts of Jest to provide a more solid testing foundation. Together with the Jest community we made a number of changes across the board that will help you get more out of Jest. We are also graduating the custom runners feature out of the experimental stage and added a new package, `jest-worker`, for parallelizing work across multiple processes. We have compiled a list of highlights below but make sure to check out the (as always) [massive changelog](https://github.com/facebook/jest/blob/master/CHANGELOG.md). +Today we are announcing a new major version of Jest which refines almost all parts of Jest to provide a more solid testing foundation. Together with the Jest community we made a number of changes across the board that will help you get more out of Jest. We are also graduating the custom runners feature out of the experimental stage and added a new package, `jest-worker`, for parallelizing work across multiple processes. We have compiled a list of highlights below but make sure to check out the (as always) [massive changelog](https://github.com/facebook/jest/blob/main/CHANGELOG.md). diff --git a/website/blog/2018-05-29-jest-23-blazing-fast-delightful-testing.md b/website/blog/2018-05-29-jest-23-blazing-fast-delightful-testing.md index 8883e9b5670c..e1a94d49645c 100644 --- a/website/blog/2018-05-29-jest-23-blazing-fast-delightful-testing.md +++ b/website/blog/2018-05-29-jest-23-blazing-fast-delightful-testing.md @@ -13,7 +13,7 @@ Here's are some of the Jest 23 highlights and breaking changes. -For a full list see the [changelog](https://github.com/facebook/jest/blob/master/CHANGELOG.md). +For a full list see the [changelog](https://github.com/facebook/jest/blob/main/CHANGELOG.md). ## Interactive Snapshot Mode diff --git a/website/blog/2019-01-25-jest-24-refreshing-polished-typescript-friendly.md b/website/blog/2019-01-25-jest-24-refreshing-polished-typescript-friendly.md index 30f0f7fbc9ad..7ce8946cc030 100644 --- a/website/blog/2019-01-25-jest-24-refreshing-polished-typescript-friendly.md +++ b/website/blog/2019-01-25-jest-24-refreshing-polished-typescript-friendly.md @@ -7,7 +7,7 @@ authorFBID: 100003004880942 Today we are happy to announce the next major release of Jest - version 24! It's been 4 months since the last minor release, and 8 months since Jest 23, so this upgrade is a big one, with something for everyone! Highlights include built-in support for TypeScript by upgrading the Jest internals to Babel 7, fixing some long-standing issues with missing console output and performance issues when computing large diffs, and a brand new sparkling website. ✨ -For a full list of all changes see the [changelog](https://github.com/facebook/jest/blob/master/CHANGELOG.md). +For a full list of all changes see the [changelog](https://github.com/facebook/jest/blob/main/CHANGELOG.md). @@ -80,7 +80,7 @@ The second one is an issue where Jest runs out of memory if the difference in se ## Breaking Changes -While all breaking changes are listed in the [changelog](https://github.com/facebook/jest/blob/master/CHANGELOG.md), there's a few of them that are worth highlighting: +While all breaking changes are listed in the [changelog](https://github.com/facebook/jest/blob/main/CHANGELOG.md), there's a few of them that are worth highlighting: - We've upgraded to Micromatch 3. While this might not affect every user, it is stricter in its parsing of globs than version 2, which is used in Jest 23. Please read through [this](https://github.com/micromatch/micromatch/issues/133#issuecomment-404211484) and linked issues for examples of invalid globs in case you have problems. - We've removed code remnants that was needed for Node 4. It was previously technically possible to run Jest 23 on Node 4 - that is no longer possible without polyfilling and transpiling. diff --git a/website/blog/2020-01-21-jest-25.md b/website/blog/2020-01-21-jest-25.md index e6deb1d0a50b..73a77367f21e 100644 --- a/website/blog/2020-01-21-jest-25.md +++ b/website/blog/2020-01-21-jest-25.md @@ -7,7 +7,7 @@ authorFBID: 100003004880942 Jest 25 is laying the groundwork for many major changes in the future. As such, we kept breaking changes to a minimum, but internal architecture changes may require attention during the upgrade. The main changes are an upgrade of JSDOM from v11 to v15, 10-15% faster test runs, a new diff view for outdated snapshots and dropped Node 6 support. -There has been more than 200 commits since Jest 24.9 by more than 80 different contributors, so as always, take a look at the [changelog](https://github.com/facebook/jest/blob/master/CHANGELOG.md) for a full list of changes. +There has been more than 200 commits since Jest 24.9 by more than 80 different contributors, so as always, take a look at the [changelog](https://github.com/facebook/jest/blob/main/CHANGELOG.md) for a full list of changes. diff --git a/website/blog/2021-05-25-jest-27.md b/website/blog/2021-05-25-jest-27.md index 1cd79c946531..f53ebaf33867 100644 --- a/website/blog/2021-05-25-jest-27.md +++ b/website/blog/2021-05-25-jest-27.md @@ -72,6 +72,6 @@ A lot of Jest's packages have been migrated to use ESM-style exports (although t We dropped support for Node 13—but Jest always supports the _Current_ and all _LTS_ [Node versions](https://nodejs.org/en/about/releases/), and Jest 27 continues to support Node 10, which only recently became unmaintained. -As always, the full changelog and list of breaking changes can be [viewed here](https://github.com/facebook/jest/blob/master/CHANGELOG.md#2700). +As always, the full changelog and list of breaking changes can be [viewed here](https://github.com/facebook/jest/blob/main/CHANGELOG.md#2700). Finally, we'd like to thank the community for once again awarding Jest a sky-high satisfaction rating of 96% in the [State of JS 2020](https://2020.stateofjs.com/en-US/technologies/testing/) survey! Stay safe everyone, and we hope you continue to enjoy using Jest in the years and versions to come! 🃏 diff --git a/website/src/pages/help.js b/website/src/pages/help.js index 6279faacdd45..6b1878bdfb99 100755 --- a/website/src/pages/help.js +++ b/website/src/pages/help.js @@ -45,7 +45,7 @@ class Help extends React.Component { {`Find out what's new with Jest. - Follow [Jest](https://twitter.com/fbjest) on Twitter. - Subscribe to the [Jest blog](/blog/). -- Look at the [changelog](https://github.com/facebook/jest/blob/master/CHANGELOG.md).`} +- Look at the [changelog](https://github.com/facebook/jest/blob/main/CHANGELOG.md).`} ), title: Stay up to date, diff --git a/website/src/pages/versions.js b/website/src/pages/versions.js index 583bf1ccef29..991996cf0771 100644 --- a/website/src/pages/versions.js +++ b/website/src/pages/versions.js @@ -36,7 +36,7 @@ export default function VersionsPage() { Documentation - + Release Notes @@ -50,7 +50,7 @@ export default function VersionsPage() { - + diff --git a/website/users.json b/website/users.json index a1b5daa0bc7b..1c4ef994e54a 100644 --- a/website/users.json +++ b/website/users.json @@ -1,5 +1,5 @@ { - "editUrl": "https://github.com/facebook/jest/edit/master/website/users.json", + "editUrl": "https://github.com/facebook/jest/edit/main/website/users.json", "users": [ { "caption": "Facebook", diff --git a/website/versioned_docs/version-25.x/Configuration.md b/website/versioned_docs/version-25.x/Configuration.md index dc100cfef6e7..cf2b740ef0bb 100644 --- a/website/versioned_docs/version-25.x/Configuration.md +++ b/website/versioned_docs/version-25.x/Configuration.md @@ -216,7 +216,7 @@ _Note: You can pass additional options to the istanbul reporter using the tuple ["json", ["lcov", {"projectRoot": "../../"}]] ``` -For the additional information about the options object shape you can refer to `CoverageReporterWithOptions` type in the [type definitions](https://github.com/facebook/jest/tree/master/packages/jest-types/src/Config.ts). +For the additional information about the options object shape you can refer to `CoverageReporterWithOptions` type in the [type definitions](https://github.com/facebook/jest/tree/main/packages/jest-types/src/Config.ts). ### `coverageThreshold` \[object] @@ -702,7 +702,7 @@ class MyCustomReporter { } ``` -For the full list of methods and argument types see `Reporter` interface in [packages/jest-reporters/src/types.ts](https://github.com/facebook/jest/blob/master/packages/jest-reporters/src/types.ts) +For the full list of methods and argument types see `Reporter` interface in [packages/jest-reporters/src/types.ts](https://github.com/facebook/jest/blob/main/packages/jest-reporters/src/types.ts) ### `resetMocks` \[boolean] @@ -915,7 +915,7 @@ Pretty foo: Object { To make a dependency explicit instead of implicit, you can call [`expect.addSnapshotSerializer`](ExpectAPI.md#expectaddsnapshotserializerserializer) to add a module for an individual test file instead of adding its path to `snapshotSerializers` in Jest configuration. -More about serializers API can be found [here](https://github.com/facebook/jest/tree/master/packages/pretty-format/README.md#serialize). +More about serializers API can be found [here](https://github.com/facebook/jest/tree/main/packages/pretty-format/README.md#serialize). ### `testEnvironment` \[string] @@ -938,7 +938,7 @@ test('use jsdom in this test file', () => { You can create your own module that will be used for setting up the test environment. The module must export a class with `setup`, `teardown` and `runScript` methods. You can also pass variables from this module to your test suites by assigning them to `this.global` object – this will make them available in your test suites as global variables. -The class may optionally expose an asynchronous `handleTestEvent` method to bind to events fired by [`jest-circus`](https://github.com/facebook/jest/tree/master/packages/jest-circus). Normally, `jest-circus` test runner would pause until a promise returned from `handleTestEvent` gets fulfilled, **except for the next events**: `start_describe_definition`, `finish_describe_definition`, `add_hook`, `add_test` or `error` (for the up-to-date list you can look at [SyncEvent type in the types definitions](https://github.com/facebook/jest/tree/master/packages/jest-types/src/Circus.ts)). That is caused by backward compatibility reasons and `process.on('unhandledRejection', callback)` signature, but that usually should not be a problem for most of the use cases. +The class may optionally expose an asynchronous `handleTestEvent` method to bind to events fired by [`jest-circus`](https://github.com/facebook/jest/tree/main/packages/jest-circus). Normally, `jest-circus` test runner would pause until a promise returned from `handleTestEvent` gets fulfilled, **except for the next events**: `start_describe_definition`, `finish_describe_definition`, `add_hook`, `add_test` or `error` (for the up-to-date list you can look at [SyncEvent type in the types definitions](https://github.com/facebook/jest/tree/main/packages/jest-types/src/Circus.ts)). That is caused by backward compatibility reasons and `process.on('unhandledRejection', callback)` signature, but that usually should not be a problem for most of the use cases. Any docblock pragmas in test files will be passed to the environment constructor and can be used for per-test configuration. If the pragma does not have a value, it will be present in the object with its value set to an empty string. If the pragma is not present, it will not be present in the object. @@ -1133,7 +1133,7 @@ function testRunner( ): Promise; ``` -An example of such function can be found in our default [jasmine2 test runner package](https://github.com/facebook/jest/blob/master/packages/jest-jasmine2/src/index.ts). +An example of such function can be found in our default [jasmine2 test runner package](https://github.com/facebook/jest/blob/main/packages/jest-jasmine2/src/index.ts). ### `testSequencer` \[string] @@ -1191,7 +1191,7 @@ Setting this value to `legacy` or `fake` enables fake timers for all tests by de Default: `{"^.+\\.[jt]sx?$": "babel-jest"}` -A map from regular expressions to paths to transformers. A transformer is a module that provides a synchronous function for transforming source files. For example, if you wanted to be able to use a new language feature in your modules or tests that aren't yet supported by node, you might plug in one of many compilers that compile a future version of JavaScript to a current one. Example: see the [examples/typescript](https://github.com/facebook/jest/blob/master/examples/typescript/package.json#L16) example or the [webpack tutorial](Webpack.md). +A map from regular expressions to paths to transformers. A transformer is a module that provides a synchronous function for transforming source files. For example, if you wanted to be able to use a new language feature in your modules or tests that aren't yet supported by node, you might plug in one of many compilers that compile a future version of JavaScript to a current one. Example: see the [examples/typescript](https://github.com/facebook/jest/blob/main/examples/typescript/package.json#L16) example or the [webpack tutorial](Webpack.md). Examples of such compilers include: @@ -1204,7 +1204,7 @@ You can pass configuration to a transformer like `{filePattern: ['path-to-transf _Note: a transformer is only run once per file unless the file has changed. During the development of a transformer it can be useful to run Jest with `--no-cache` to frequently [delete Jest's cache](Troubleshooting.md#caching-issues)._ -_Note: when adding additional code transformers, this will overwrite the default config and `babel-jest` is no longer automatically loaded. If you want to use it to compile JavaScript or Typescript, it has to be explicitly defined by adding `{"\\.[jt]sx?$": "babel-jest"}` to the transform property. See [babel-jest plugin](https://github.com/facebook/jest/tree/master/packages/babel-jest#setup)_ +_Note: when adding additional code transformers, this will overwrite the default config and `babel-jest` is no longer automatically loaded. If you want to use it to compile JavaScript or Typescript, it has to be explicitly defined by adding `{"\\.[jt]sx?$": "babel-jest"}` to the transform property. See [babel-jest plugin](https://github.com/facebook/jest/tree/main/packages/babel-jest#setup)_ ### `transformIgnorePatterns` \[array<string>] diff --git a/website/versioned_docs/version-25.x/ExpectAPI.md b/website/versioned_docs/version-25.x/ExpectAPI.md index 1cd94b7aa1d2..44974ca9c411 100644 --- a/website/versioned_docs/version-25.x/ExpectAPI.md +++ b/website/versioned_docs/version-25.x/ExpectAPI.md @@ -151,7 +151,7 @@ A boolean to let you know this matcher was called with an `expand` option. When #### `this.utils` -There are a number of helpful tools exposed on `this.utils` primarily consisting of the exports from [`jest-matcher-utils`](https://github.com/facebook/jest/tree/master/packages/jest-matcher-utils). +There are a number of helpful tools exposed on `this.utils` primarily consisting of the exports from [`jest-matcher-utils`](https://github.com/facebook/jest/tree/main/packages/jest-matcher-utils). The most useful ones are `matcherHint`, `printExpected` and `printReceived` to format the error messages nicely. For example, take a look at the implementation for the `toBe` matcher: diff --git a/website/versioned_docs/version-25.x/JestObjectAPI.md b/website/versioned_docs/version-25.x/JestObjectAPI.md index 58b4de2f9452..55a917075757 100644 --- a/website/versioned_docs/version-25.x/JestObjectAPI.md +++ b/website/versioned_docs/version-25.x/JestObjectAPI.md @@ -656,7 +656,7 @@ jest.setTimeout(1000); // 1 second ### `jest.retryTimes()` -Runs failed tests n-times until they pass or until the max number of retries is exhausted. This only works with [jest-circus](https://github.com/facebook/jest/tree/master/packages/jest-circus)! +Runs failed tests n-times until they pass or until the max number of retries is exhausted. This only works with [jest-circus](https://github.com/facebook/jest/tree/main/packages/jest-circus)! Example in a test: diff --git a/website/versioned_docs/version-25.x/JestPlatform.md b/website/versioned_docs/version-25.x/JestPlatform.md index 8a544be07e97..568b39317aa5 100644 --- a/website/versioned_docs/version-25.x/JestPlatform.md +++ b/website/versioned_docs/version-25.x/JestPlatform.md @@ -23,7 +23,7 @@ getChangedFilesForRoots(['./'], { }).then(result => console.log(result.changedFiles)); ``` -You can read more about `jest-changed-files` in the [readme file](https://github.com/facebook/jest/blob/master/packages/jest-changed-files/README.md). +You can read more about `jest-changed-files` in the [readme file](https://github.com/facebook/jest/blob/main/packages/jest-changed-files/README.md). ## jest-diff @@ -68,7 +68,7 @@ const parsed = parseWithComments(code); console.log(parsed); ``` -You can read more about `jest-docblock` in the [readme file](https://github.com/facebook/jest/blob/master/packages/jest-docblock/README.md). +You can read more about `jest-docblock` in the [readme file](https://github.com/facebook/jest/blob/main/packages/jest-docblock/README.md). ## jest-get-type @@ -115,7 +115,7 @@ const result = validate(configByUser, { console.log(result); ``` -You can read more about `jest-validate` in the [readme file](https://github.com/facebook/jest/blob/master/packages/jest-validate/README.md). +You can read more about `jest-validate` in the [readme file](https://github.com/facebook/jest/blob/main/packages/jest-validate/README.md). ## jest-worker @@ -151,7 +151,7 @@ async function main() { main(); ``` -You can read more about `jest-worker` in the [readme file](https://github.com/facebook/jest/blob/master/packages/jest-worker/README.md). +You can read more about `jest-worker` in the [readme file](https://github.com/facebook/jest/blob/main/packages/jest-worker/README.md). ## pretty-format @@ -171,4 +171,4 @@ val.array = [-0, Infinity, NaN]; console.log(prettyFormat(val)); ``` -You can read more about `pretty-format` in the [readme file](https://github.com/facebook/jest/blob/master/packages/pretty-format/README.md). +You can read more about `pretty-format` in the [readme file](https://github.com/facebook/jest/blob/main/packages/pretty-format/README.md). diff --git a/website/versioned_docs/version-25.x/ManualMocks.md b/website/versioned_docs/version-25.x/ManualMocks.md index e86c9dee2d9a..2f58f0606375 100644 --- a/website/versioned_docs/version-25.x/ManualMocks.md +++ b/website/versioned_docs/version-25.x/ManualMocks.md @@ -127,7 +127,7 @@ The example mock shown here uses [`jest.genMockFromModule`](JestObjectAPI.md#jes 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)`](JestObjectAPI.md#jestrequireactualmodulename) 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). +The code for this example is available at [examples/manual-mocks](https://github.com/facebook/jest/tree/main/examples/manual-mocks). ## Using with ES module imports diff --git a/website/versioned_docs/version-25.x/MockFunctionAPI.md b/website/versioned_docs/version-25.x/MockFunctionAPI.md index fb2672b08fa6..3cc228fd7880 100644 --- a/website/versioned_docs/version-25.x/MockFunctionAPI.md +++ b/website/versioned_docs/version-25.x/MockFunctionAPI.md @@ -327,7 +327,7 @@ If you are using [Create React App](https://create-react-app.dev) then the [Type Otherwise, please see our [Getting Started](GettingStarted.md#using-typescript) guide for to get setup with TypeScript. -You can see an example of using Jest with TypeScript in our [GitHub repository](https://github.com/facebook/jest/tree/master/examples/typescript). +You can see an example of using Jest with TypeScript in our [GitHub repository](https://github.com/facebook/jest/tree/main/examples/typescript). ### `jest.MockedFunction` diff --git a/website/versioned_docs/version-25.x/MoreResources.md b/website/versioned_docs/version-25.x/MoreResources.md index c9d0968eeae3..cc0f85804cd8 100644 --- a/website/versioned_docs/version-25.x/MoreResources.md +++ b/website/versioned_docs/version-25.x/MoreResources.md @@ -15,7 +15,7 @@ By now you should have a good idea of how Jest can help you test your applicatio ## Learn by example -You will find a number of example test cases in the [`examples`](https://github.com/facebook/jest/tree/master/examples) folder on GitHub. You can also learn from the excellent tests used by the [React](https://github.com/facebook/react/tree/master/packages/react/src/__tests__), [Relay](https://github.com/facebook/relay/tree/master/packages/react-relay/__tests__), and [React Native](https://github.com/facebook/react-native/tree/master/Libraries/Animated/src/__tests__) projects. +You will find a number of example test cases in the [`examples`](https://github.com/facebook/jest/tree/main/examples) folder on GitHub. You can also learn from the excellent tests used by the [React](https://github.com/facebook/react/tree/main/packages/react/src/__tests__), [Relay](https://github.com/facebook/relay/tree/main/packages/react-relay/__tests__), and [React Native](https://github.com/facebook/react-native/tree/main/Libraries/Animated/src/__tests__) projects. ## Join the community diff --git a/website/versioned_docs/version-25.x/SnapshotTesting.md b/website/versioned_docs/version-25.x/SnapshotTesting.md index 6907cbdea53a..d06b6e067ba3 100644 --- a/website/versioned_docs/version-25.x/SnapshotTesting.md +++ b/website/versioned_docs/version-25.x/SnapshotTesting.md @@ -9,7 +9,7 @@ A typical snapshot test case renders a UI component, takes a snapshot, then comp ## Snapshot Testing with Jest -A similar approach can be taken when it comes to testing your React components. Instead of rendering the graphical UI, which would require building the entire app, you can use a test renderer to quickly generate a serializable value for your React tree. Consider this [example test](https://github.com/facebook/jest/blob/master/examples/snapshot/__tests__/link.react.test.js) for a [Link component](https://github.com/facebook/jest/blob/master/examples/snapshot/Link.react.js): +A similar approach can be taken when it comes to testing your React components. Instead of rendering the graphical UI, which would require building the entire app, you can use a test renderer to quickly generate a serializable value for your React tree. Consider this [example test](https://github.com/facebook/jest/blob/main/examples/snapshot/__tests__/link.react.test.js) for a [Link component](https://github.com/facebook/jest/blob/main/examples/snapshot/Link.react.js): ```tsx import React from 'react'; @@ -24,7 +24,7 @@ it('renders correctly', () => { }); ``` -The first time this test is run, Jest creates a [snapshot file](https://github.com/facebook/jest/blob/master/examples/snapshot/__tests__/__snapshots__/link.react.test.js.snap) that looks like this: +The first time this test is run, Jest creates a [snapshot file](https://github.com/facebook/jest/blob/main/examples/snapshot/__tests__/__snapshots__/link.react.test.js.snap) that looks like this: ```javascript exports[`renders correctly 1`] = ` @@ -39,7 +39,7 @@ exports[`renders correctly 1`] = ` `; ``` -The snapshot artifact should be committed alongside code changes, and reviewed as part of your code review process. Jest uses [pretty-format](https://github.com/facebook/jest/tree/master/packages/pretty-format) to make snapshots human-readable during code review. On subsequent test runs, Jest will compare the rendered output with the previous snapshot. If they match, the test will pass. If they don't match, either the test runner found a bug in your code (in the `` component in this case) that should be fixed, or the implementation has changed and the snapshot needs to be updated. +The snapshot artifact should be committed alongside code changes, and reviewed as part of your code review process. Jest uses [pretty-format](https://github.com/facebook/jest/tree/main/packages/pretty-format) to make snapshots human-readable during code review. On subsequent test runs, Jest will compare the rendered output with the previous snapshot. If they match, the test will pass. If they don't match, either the test runner found a bug in your code (in the `` component in this case) that should be fixed, or the implementation has changed and the snapshot needs to be updated. > Note: The snapshot is directly scoped to the data you render – in our example the `` component with `page` prop passed to it. This implies that even if any other file has missing props (Say, `App.js`) in the `` component, it will still pass the test as the test doesn't know the usage of `` component and it's scoped only to the `Link.react.js`. Also, Rendering the same component with different props in other snapshot tests will not affect the first one, as the tests don't know about each other. @@ -77,7 +77,7 @@ Go ahead and accept the changes by running the above command. You may also use t If you'd like to limit which snapshot test cases get re-generated, you can pass an additional `--testNamePattern` flag to re-record snapshots only for those tests that match the pattern. -You can try out this functionality by cloning the [snapshot example](https://github.com/facebook/jest/tree/master/examples/snapshot), modifying the `Link` component, and running Jest. +You can try out this functionality by cloning the [snapshot example](https://github.com/facebook/jest/tree/main/examples/snapshot), modifying the `Link` component, and running Jest. ### Interactive Snapshot Mode @@ -223,7 +223,7 @@ Commit snapshots and review them as part of your regular code review process. Th Ensure that your snapshots are readable by keeping them focused, short, and by using tools that enforce these stylistic conventions. -As mentioned previously, Jest uses [`pretty-format`](https://yarnpkg.com/en/package/pretty-format) to make snapshots human-readable, but you may find it useful to introduce additional tools, like [`eslint-plugin-jest`](https://yarnpkg.com/en/package/eslint-plugin-jest) with its [`no-large-snapshots`](https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules/no-large-snapshots.md) option, or [`snapshot-diff`](https://yarnpkg.com/en/package/snapshot-diff) with its component snapshot comparison feature, to promote committing short, focused assertions. +As mentioned previously, Jest uses [`pretty-format`](https://yarnpkg.com/en/package/pretty-format) to make snapshots human-readable, but you may find it useful to introduce additional tools, like [`eslint-plugin-jest`](https://yarnpkg.com/en/package/eslint-plugin-jest) with its [`no-large-snapshots`](https://github.com/jest-community/eslint-plugin-jest/blob/main/docs/rules/no-large-snapshots.md) option, or [`snapshot-diff`](https://yarnpkg.com/en/package/snapshot-diff) with its component snapshot comparison feature, to promote committing short, focused assertions. The goal is to make it easy to review snapshots in pull requests, and fight against the habit of regenerating snapshots when test suites fail instead of examining the root causes of their failure. @@ -231,7 +231,7 @@ The goal is to make it easy to review snapshots in pull requests, and fight agai Your tests should be deterministic. Running the same tests multiple times on a component that has not changed should produce the same results every time. You're responsible for making sure your generated snapshots do not include platform specific or other non-deterministic data. -For example, if you have a [Clock](https://github.com/facebook/jest/blob/master/examples/snapshot/Clock.react.js) component that uses `Date.now()`, the snapshot generated from this component will be different every time the test case is run. In this case we can [mock the Date.now() method](MockFunctions.md) to return a consistent value every time the test is run: +For example, if you have a [Clock](https://github.com/facebook/jest/blob/main/examples/snapshot/Clock.react.js) component that uses `Date.now()`, the snapshot generated from this component will be different every time the test case is run. In this case we can [mock the Date.now() method](MockFunctions.md) to return a consistent value every time the test is run: ```js Date.now = jest.fn(() => 1482363367071); @@ -291,7 +291,7 @@ Yes, all snapshot files should be committed alongside the modules they are cover ### Does snapshot testing only work with React components? -[React](TutorialReact.md) and [React Native](TutorialReactNative.md) components are a good use case for snapshot testing. However, snapshots can capture any serializable value and should be used anytime the goal is testing whether the output is correct. The Jest repository contains many examples of testing the output of Jest itself, the output of Jest's assertion library as well as log messages from various parts of the Jest codebase. See an example of [snapshotting CLI output](https://github.com/facebook/jest/blob/master/e2e/__tests__/console.test.ts) in the Jest repo. +[React](TutorialReact.md) and [React Native](TutorialReactNative.md) components are a good use case for snapshot testing. However, snapshots can capture any serializable value and should be used anytime the goal is testing whether the output is correct. The Jest repository contains many examples of testing the output of Jest itself, the output of Jest's assertion library as well as log messages from various parts of the Jest codebase. See an example of [snapshotting CLI output](https://github.com/facebook/jest/blob/main/e2e/__tests__/console.test.ts) in the Jest repo. ### What's the difference between snapshot testing and visual regression testing? diff --git a/website/versioned_docs/version-25.x/TimerMocks.md b/website/versioned_docs/version-25.x/TimerMocks.md index 75d875ea08fe..89f2066d82c3 100644 --- a/website/versioned_docs/version-25.x/TimerMocks.md +++ b/website/versioned_docs/version-25.x/TimerMocks.md @@ -160,4 +160,4 @@ it('calls the callback after 1 second via advanceTimersByTime', () => { Lastly, it may occasionally be useful in some tests to be able to clear all of the pending timers. For this, we have `jest.clearAllTimers()`. -The code for this example is available at [examples/timer](https://github.com/facebook/jest/tree/master/examples/timer). +The code for this example is available at [examples/timer](https://github.com/facebook/jest/tree/main/examples/timer). diff --git a/website/versioned_docs/version-25.x/TutorialAsync.md b/website/versioned_docs/version-25.x/TutorialAsync.md index 969d673a6532..dd8a2da77977 100644 --- a/website/versioned_docs/version-25.x/TutorialAsync.md +++ b/website/versioned_docs/version-25.x/TutorialAsync.md @@ -160,6 +160,6 @@ it('tests error with async/await and rejects', async () => { }); ``` -The code for this example is available at [examples/async](https://github.com/facebook/jest/tree/master/examples/async). +The code for this example is available at [examples/async](https://github.com/facebook/jest/tree/main/examples/async). If you'd like to test timers, like `setTimeout`, take a look at the [Timer mocks](TimerMocks.md) documentation. diff --git a/website/versioned_docs/version-25.x/TutorialReact.md b/website/versioned_docs/version-25.x/TutorialReact.md index 8fe4abc91007..d6be521ae589 100644 --- a/website/versioned_docs/version-25.x/TutorialReact.md +++ b/website/versioned_docs/version-25.x/TutorialReact.md @@ -162,7 +162,7 @@ exports[`Link changes the class when hovered 3`] = ` The next time you run the tests, the rendered output will be compared to the previously created snapshot. The snapshot should be committed along with code changes. When a snapshot test fails, you need to inspect whether it is an intended or unintended change. If the change is expected you can invoke Jest with `jest -u` to overwrite the existing snapshot. -The code for this example is available at [examples/snapshot](https://github.com/facebook/jest/tree/master/examples/snapshot). +The code for this example is available at [examples/snapshot](https://github.com/facebook/jest/tree/main/examples/snapshot). #### Snapshot Testing with Mocks, Enzyme and React 16 @@ -253,7 +253,7 @@ it('CheckboxWithLabel changes the text after click', () => { }); ``` -The code for this example is available at [examples/react-testing-library](https://github.com/facebook/jest/tree/master/examples/react-testing-library). +The code for this example is available at [examples/react-testing-library](https://github.com/facebook/jest/tree/main/examples/react-testing-library). #### Enzyme @@ -280,7 +280,7 @@ test('CheckboxWithLabel changes the text after click', () => { }); ``` -The code for this example is available at [examples/enzyme](https://github.com/facebook/jest/tree/master/examples/enzyme). +The code for this example is available at [examples/enzyme](https://github.com/facebook/jest/tree/main/examples/enzyme). ### Custom transformers diff --git a/website/versioned_docs/version-25.x/TutorialReactNative.md b/website/versioned_docs/version-25.x/TutorialReactNative.md index 5c806ff26bb9..d6c0fbf56860 100644 --- a/website/versioned_docs/version-25.x/TutorialReactNative.md +++ b/website/versioned_docs/version-25.x/TutorialReactNative.md @@ -124,7 +124,7 @@ exports[`Intro renders correctly 1`] = ` The next time you run the tests, the rendered output will be compared to the previously created snapshot. The snapshot should be committed along with code changes. When a snapshot test fails, you need to inspect whether it is an intended or unintended change. If the change is expected you can invoke Jest with `jest -u` to overwrite the existing snapshot. -The code for this example is available at [examples/react-native](https://github.com/facebook/jest/tree/master/examples/react-native). +The code for this example is available at [examples/react-native](https://github.com/facebook/jest/tree/main/examples/react-native). ## Preset configuration diff --git a/website/versioned_docs/version-25.x/TutorialjQuery.md b/website/versioned_docs/version-25.x/TutorialjQuery.md index fea33d6eb703..7532f285918f 100644 --- a/website/versioned_docs/version-25.x/TutorialjQuery.md +++ b/website/versioned_docs/version-25.x/TutorialjQuery.md @@ -65,4 +65,4 @@ The function being tested adds an event listener on the `#button` DOM element, s We are mocking `fetchCurrentUser.js` so that our test doesn't make a real network request but instead resolves to mock data locally. This ensures that our test can complete in milliseconds rather than seconds and guarantees a fast unit test iteration speed. -The code for this example is available at [examples/jquery](https://github.com/facebook/jest/tree/master/examples/jquery). +The code for this example is available at [examples/jquery](https://github.com/facebook/jest/tree/main/examples/jquery). diff --git a/website/versioned_docs/version-26.x/Configuration.md b/website/versioned_docs/version-26.x/Configuration.md index 4091301b32f3..d05695252606 100644 --- a/website/versioned_docs/version-26.x/Configuration.md +++ b/website/versioned_docs/version-26.x/Configuration.md @@ -234,7 +234,7 @@ _Note: You can pass additional options to the istanbul reporter using the tuple ["json", ["lcov", {"projectRoot": "../../"}]] ``` -For the additional information about the options object shape you can refer to `CoverageReporterWithOptions` type in the [type definitions](https://github.com/facebook/jest/tree/master/packages/jest-types/src/Config.ts). +For the additional information about the options object shape you can refer to `CoverageReporterWithOptions` type in the [type definitions](https://github.com/facebook/jest/tree/main/packages/jest-types/src/Config.ts). ### `coverageThreshold` \[object] @@ -738,7 +738,7 @@ class MyCustomReporter { } ``` -For the full list of methods and argument types see `Reporter` interface in [packages/jest-reporters/src/types.ts](https://github.com/facebook/jest/blob/master/packages/jest-reporters/src/types.ts) +For the full list of methods and argument types see `Reporter` interface in [packages/jest-reporters/src/types.ts](https://github.com/facebook/jest/blob/main/packages/jest-reporters/src/types.ts) ### `resetMocks` \[boolean] @@ -1005,7 +1005,7 @@ Pretty foo: Object { To make a dependency explicit instead of implicit, you can call [`expect.addSnapshotSerializer`](ExpectAPI.md#expectaddsnapshotserializerserializer) to add a module for an individual test file instead of adding its path to `snapshotSerializers` in Jest configuration. -More about serializers API can be found [here](https://github.com/facebook/jest/tree/master/packages/pretty-format/README.md#serialize). +More about serializers API can be found [here](https://github.com/facebook/jest/tree/main/packages/pretty-format/README.md#serialize). ### `testEnvironment` \[string] @@ -1028,7 +1028,7 @@ test('use jsdom in this test file', () => { You can create your own module that will be used for setting up the test environment. The module must export a class with `setup`, `teardown` and `runScript` methods. You can also pass variables from this module to your test suites by assigning them to `this.global` object – this will make them available in your test suites as global variables. -The class may optionally expose an asynchronous `handleTestEvent` method to bind to events fired by [`jest-circus`](https://github.com/facebook/jest/tree/master/packages/jest-circus). Normally, `jest-circus` test runner would pause until a promise returned from `handleTestEvent` gets fulfilled, **except for the next events**: `start_describe_definition`, `finish_describe_definition`, `add_hook`, `add_test` or `error` (for the up-to-date list you can look at [SyncEvent type in the types definitions](https://github.com/facebook/jest/tree/master/packages/jest-types/src/Circus.ts)). That is caused by backward compatibility reasons and `process.on('unhandledRejection', callback)` signature, but that usually should not be a problem for most of the use cases. +The class may optionally expose an asynchronous `handleTestEvent` method to bind to events fired by [`jest-circus`](https://github.com/facebook/jest/tree/main/packages/jest-circus). Normally, `jest-circus` test runner would pause until a promise returned from `handleTestEvent` gets fulfilled, **except for the next events**: `start_describe_definition`, `finish_describe_definition`, `add_hook`, `add_test` or `error` (for the up-to-date list you can look at [SyncEvent type in the types definitions](https://github.com/facebook/jest/tree/main/packages/jest-types/src/Circus.ts)). That is caused by backward compatibility reasons and `process.on('unhandledRejection', callback)` signature, but that usually should not be a problem for most of the use cases. Any docblock pragmas in test files will be passed to the environment constructor and can be used for per-test configuration. If the pragma does not have a value, it will be present in the object with its value set to an empty string. If the pragma is not present, it will not be present in the object. @@ -1223,7 +1223,7 @@ function testRunner( ): Promise; ``` -An example of such function can be found in our default [jasmine2 test runner package](https://github.com/facebook/jest/blob/master/packages/jest-jasmine2/src/index.ts). +An example of such function can be found in our default [jasmine2 test runner package](https://github.com/facebook/jest/blob/main/packages/jest-jasmine2/src/index.ts). ### `testSequencer` \[string] @@ -1283,7 +1283,7 @@ If the value is `modern`, [`@sinonjs/fake-timers`](https://github.com/sinonjs/fa Default: `{"\\.[jt]sx?$": "babel-jest"}` -A map from regular expressions to paths to transformers. A transformer is a module that provides a synchronous function for transforming source files. For example, if you wanted to be able to use a new language feature in your modules or tests that aren't yet supported by node, you might plug in one of many compilers that compile a future version of JavaScript to a current one. Example: see the [examples/typescript](https://github.com/facebook/jest/blob/master/examples/typescript/package.json#L16) example or the [webpack tutorial](Webpack.md). +A map from regular expressions to paths to transformers. A transformer is a module that provides a synchronous function for transforming source files. For example, if you wanted to be able to use a new language feature in your modules or tests that aren't yet supported by node, you might plug in one of many compilers that compile a future version of JavaScript to a current one. Example: see the [examples/typescript](https://github.com/facebook/jest/blob/main/examples/typescript/package.json#L16) example or the [webpack tutorial](Webpack.md). Examples of such compilers include: @@ -1296,7 +1296,7 @@ You can pass configuration to a transformer like `{filePattern: ['path-to-transf _Note: a transformer is only run once per file unless the file has changed. During the development of a transformer it can be useful to run Jest with `--no-cache` to frequently [delete Jest's cache](Troubleshooting.md#caching-issues)._ -_Note: when adding additional code transformers, this will overwrite the default config and `babel-jest` is no longer automatically loaded. If you want to use it to compile JavaScript or Typescript, it has to be explicitly defined by adding `{"\\.[jt]sx?$": "babel-jest"}` to the transform property. See [babel-jest plugin](https://github.com/facebook/jest/tree/master/packages/babel-jest#setup)_ +_Note: when adding additional code transformers, this will overwrite the default config and `babel-jest` is no longer automatically loaded. If you want to use it to compile JavaScript or Typescript, it has to be explicitly defined by adding `{"\\.[jt]sx?$": "babel-jest"}` to the transform property. See [babel-jest plugin](https://github.com/facebook/jest/tree/main/packages/babel-jest#setup)_ ### `transformIgnorePatterns` \[array<string>] diff --git a/website/versioned_docs/version-26.x/ExpectAPI.md b/website/versioned_docs/version-26.x/ExpectAPI.md index 272d707236b9..a66d982bbba3 100644 --- a/website/versioned_docs/version-26.x/ExpectAPI.md +++ b/website/versioned_docs/version-26.x/ExpectAPI.md @@ -151,7 +151,7 @@ A boolean to let you know this matcher was called with an `expand` option. When #### `this.utils` -There are a number of helpful tools exposed on `this.utils` primarily consisting of the exports from [`jest-matcher-utils`](https://github.com/facebook/jest/tree/master/packages/jest-matcher-utils). +There are a number of helpful tools exposed on `this.utils` primarily consisting of the exports from [`jest-matcher-utils`](https://github.com/facebook/jest/tree/main/packages/jest-matcher-utils). The most useful ones are `matcherHint`, `printExpected` and `printReceived` to format the error messages nicely. For example, take a look at the implementation for the `toBe` matcher: diff --git a/website/versioned_docs/version-26.x/JestObjectAPI.md b/website/versioned_docs/version-26.x/JestObjectAPI.md index ae980e80c9ee..d1a2f1ec15f3 100644 --- a/website/versioned_docs/version-26.x/JestObjectAPI.md +++ b/website/versioned_docs/version-26.x/JestObjectAPI.md @@ -676,7 +676,7 @@ jest.setTimeout(1000); // 1 second ### `jest.retryTimes()` -Runs failed tests n-times until they pass or until the max number of retries is exhausted. This only works with [jest-circus](https://github.com/facebook/jest/tree/master/packages/jest-circus)! +Runs failed tests n-times until they pass or until the max number of retries is exhausted. This only works with [jest-circus](https://github.com/facebook/jest/tree/main/packages/jest-circus)! Example in a test: diff --git a/website/versioned_docs/version-26.x/JestPlatform.md b/website/versioned_docs/version-26.x/JestPlatform.md index 648acb758943..3066711bc5e0 100644 --- a/website/versioned_docs/version-26.x/JestPlatform.md +++ b/website/versioned_docs/version-26.x/JestPlatform.md @@ -23,7 +23,7 @@ getChangedFilesForRoots(['./'], { }).then(result => console.log(result.changedFiles)); ``` -You can read more about `jest-changed-files` in the [readme file](https://github.com/facebook/jest/blob/master/packages/jest-changed-files/README.md). +You can read more about `jest-changed-files` in the [readme file](https://github.com/facebook/jest/blob/main/packages/jest-changed-files/README.md). ## jest-diff @@ -68,7 +68,7 @@ const parsed = parseWithComments(code); console.log(parsed); ``` -You can read more about `jest-docblock` in the [readme file](https://github.com/facebook/jest/blob/master/packages/jest-docblock/README.md). +You can read more about `jest-docblock` in the [readme file](https://github.com/facebook/jest/blob/main/packages/jest-docblock/README.md). ## jest-get-type @@ -115,7 +115,7 @@ const result = validate(configByUser, { console.log(result); ``` -You can read more about `jest-validate` in the [readme file](https://github.com/facebook/jest/blob/master/packages/jest-validate/README.md). +You can read more about `jest-validate` in the [readme file](https://github.com/facebook/jest/blob/main/packages/jest-validate/README.md). ## jest-worker @@ -151,7 +151,7 @@ async function main() { main(); ``` -You can read more about `jest-worker` in the [readme file](https://github.com/facebook/jest/blob/master/packages/jest-worker/README.md). +You can read more about `jest-worker` in the [readme file](https://github.com/facebook/jest/blob/main/packages/jest-worker/README.md). ## pretty-format @@ -171,4 +171,4 @@ val.array = [-0, Infinity, NaN]; console.log(prettyFormat(val)); ``` -You can read more about `pretty-format` in the [readme file](https://github.com/facebook/jest/blob/master/packages/pretty-format/README.md). +You can read more about `pretty-format` in the [readme file](https://github.com/facebook/jest/blob/main/packages/pretty-format/README.md). diff --git a/website/versioned_docs/version-26.x/ManualMocks.md b/website/versioned_docs/version-26.x/ManualMocks.md index 4732d3d10cd4..d481a5712e49 100644 --- a/website/versioned_docs/version-26.x/ManualMocks.md +++ b/website/versioned_docs/version-26.x/ManualMocks.md @@ -127,7 +127,7 @@ The example mock shown here uses [`jest.createMockFromModule`](JestObjectAPI.md# 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)`](JestObjectAPI.md#jestrequireactualmodulename) 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). +The code for this example is available at [examples/manual-mocks](https://github.com/facebook/jest/tree/main/examples/manual-mocks). ## Using with ES module imports diff --git a/website/versioned_docs/version-26.x/MockFunctionAPI.md b/website/versioned_docs/version-26.x/MockFunctionAPI.md index fb2672b08fa6..3cc228fd7880 100644 --- a/website/versioned_docs/version-26.x/MockFunctionAPI.md +++ b/website/versioned_docs/version-26.x/MockFunctionAPI.md @@ -327,7 +327,7 @@ If you are using [Create React App](https://create-react-app.dev) then the [Type Otherwise, please see our [Getting Started](GettingStarted.md#using-typescript) guide for to get setup with TypeScript. -You can see an example of using Jest with TypeScript in our [GitHub repository](https://github.com/facebook/jest/tree/master/examples/typescript). +You can see an example of using Jest with TypeScript in our [GitHub repository](https://github.com/facebook/jest/tree/main/examples/typescript). ### `jest.MockedFunction` diff --git a/website/versioned_docs/version-26.x/MoreResources.md b/website/versioned_docs/version-26.x/MoreResources.md index c9d0968eeae3..cc0f85804cd8 100644 --- a/website/versioned_docs/version-26.x/MoreResources.md +++ b/website/versioned_docs/version-26.x/MoreResources.md @@ -15,7 +15,7 @@ By now you should have a good idea of how Jest can help you test your applicatio ## Learn by example -You will find a number of example test cases in the [`examples`](https://github.com/facebook/jest/tree/master/examples) folder on GitHub. You can also learn from the excellent tests used by the [React](https://github.com/facebook/react/tree/master/packages/react/src/__tests__), [Relay](https://github.com/facebook/relay/tree/master/packages/react-relay/__tests__), and [React Native](https://github.com/facebook/react-native/tree/master/Libraries/Animated/src/__tests__) projects. +You will find a number of example test cases in the [`examples`](https://github.com/facebook/jest/tree/main/examples) folder on GitHub. You can also learn from the excellent tests used by the [React](https://github.com/facebook/react/tree/main/packages/react/src/__tests__), [Relay](https://github.com/facebook/relay/tree/main/packages/react-relay/__tests__), and [React Native](https://github.com/facebook/react-native/tree/main/Libraries/Animated/src/__tests__) projects. ## Join the community diff --git a/website/versioned_docs/version-26.x/SnapshotTesting.md b/website/versioned_docs/version-26.x/SnapshotTesting.md index 6907cbdea53a..d06b6e067ba3 100644 --- a/website/versioned_docs/version-26.x/SnapshotTesting.md +++ b/website/versioned_docs/version-26.x/SnapshotTesting.md @@ -9,7 +9,7 @@ A typical snapshot test case renders a UI component, takes a snapshot, then comp ## Snapshot Testing with Jest -A similar approach can be taken when it comes to testing your React components. Instead of rendering the graphical UI, which would require building the entire app, you can use a test renderer to quickly generate a serializable value for your React tree. Consider this [example test](https://github.com/facebook/jest/blob/master/examples/snapshot/__tests__/link.react.test.js) for a [Link component](https://github.com/facebook/jest/blob/master/examples/snapshot/Link.react.js): +A similar approach can be taken when it comes to testing your React components. Instead of rendering the graphical UI, which would require building the entire app, you can use a test renderer to quickly generate a serializable value for your React tree. Consider this [example test](https://github.com/facebook/jest/blob/main/examples/snapshot/__tests__/link.react.test.js) for a [Link component](https://github.com/facebook/jest/blob/main/examples/snapshot/Link.react.js): ```tsx import React from 'react'; @@ -24,7 +24,7 @@ it('renders correctly', () => { }); ``` -The first time this test is run, Jest creates a [snapshot file](https://github.com/facebook/jest/blob/master/examples/snapshot/__tests__/__snapshots__/link.react.test.js.snap) that looks like this: +The first time this test is run, Jest creates a [snapshot file](https://github.com/facebook/jest/blob/main/examples/snapshot/__tests__/__snapshots__/link.react.test.js.snap) that looks like this: ```javascript exports[`renders correctly 1`] = ` @@ -39,7 +39,7 @@ exports[`renders correctly 1`] = ` `; ``` -The snapshot artifact should be committed alongside code changes, and reviewed as part of your code review process. Jest uses [pretty-format](https://github.com/facebook/jest/tree/master/packages/pretty-format) to make snapshots human-readable during code review. On subsequent test runs, Jest will compare the rendered output with the previous snapshot. If they match, the test will pass. If they don't match, either the test runner found a bug in your code (in the `` component in this case) that should be fixed, or the implementation has changed and the snapshot needs to be updated. +The snapshot artifact should be committed alongside code changes, and reviewed as part of your code review process. Jest uses [pretty-format](https://github.com/facebook/jest/tree/main/packages/pretty-format) to make snapshots human-readable during code review. On subsequent test runs, Jest will compare the rendered output with the previous snapshot. If they match, the test will pass. If they don't match, either the test runner found a bug in your code (in the `` component in this case) that should be fixed, or the implementation has changed and the snapshot needs to be updated. > Note: The snapshot is directly scoped to the data you render – in our example the `` component with `page` prop passed to it. This implies that even if any other file has missing props (Say, `App.js`) in the `` component, it will still pass the test as the test doesn't know the usage of `` component and it's scoped only to the `Link.react.js`. Also, Rendering the same component with different props in other snapshot tests will not affect the first one, as the tests don't know about each other. @@ -77,7 +77,7 @@ Go ahead and accept the changes by running the above command. You may also use t If you'd like to limit which snapshot test cases get re-generated, you can pass an additional `--testNamePattern` flag to re-record snapshots only for those tests that match the pattern. -You can try out this functionality by cloning the [snapshot example](https://github.com/facebook/jest/tree/master/examples/snapshot), modifying the `Link` component, and running Jest. +You can try out this functionality by cloning the [snapshot example](https://github.com/facebook/jest/tree/main/examples/snapshot), modifying the `Link` component, and running Jest. ### Interactive Snapshot Mode @@ -223,7 +223,7 @@ Commit snapshots and review them as part of your regular code review process. Th Ensure that your snapshots are readable by keeping them focused, short, and by using tools that enforce these stylistic conventions. -As mentioned previously, Jest uses [`pretty-format`](https://yarnpkg.com/en/package/pretty-format) to make snapshots human-readable, but you may find it useful to introduce additional tools, like [`eslint-plugin-jest`](https://yarnpkg.com/en/package/eslint-plugin-jest) with its [`no-large-snapshots`](https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules/no-large-snapshots.md) option, or [`snapshot-diff`](https://yarnpkg.com/en/package/snapshot-diff) with its component snapshot comparison feature, to promote committing short, focused assertions. +As mentioned previously, Jest uses [`pretty-format`](https://yarnpkg.com/en/package/pretty-format) to make snapshots human-readable, but you may find it useful to introduce additional tools, like [`eslint-plugin-jest`](https://yarnpkg.com/en/package/eslint-plugin-jest) with its [`no-large-snapshots`](https://github.com/jest-community/eslint-plugin-jest/blob/main/docs/rules/no-large-snapshots.md) option, or [`snapshot-diff`](https://yarnpkg.com/en/package/snapshot-diff) with its component snapshot comparison feature, to promote committing short, focused assertions. The goal is to make it easy to review snapshots in pull requests, and fight against the habit of regenerating snapshots when test suites fail instead of examining the root causes of their failure. @@ -231,7 +231,7 @@ The goal is to make it easy to review snapshots in pull requests, and fight agai Your tests should be deterministic. Running the same tests multiple times on a component that has not changed should produce the same results every time. You're responsible for making sure your generated snapshots do not include platform specific or other non-deterministic data. -For example, if you have a [Clock](https://github.com/facebook/jest/blob/master/examples/snapshot/Clock.react.js) component that uses `Date.now()`, the snapshot generated from this component will be different every time the test case is run. In this case we can [mock the Date.now() method](MockFunctions.md) to return a consistent value every time the test is run: +For example, if you have a [Clock](https://github.com/facebook/jest/blob/main/examples/snapshot/Clock.react.js) component that uses `Date.now()`, the snapshot generated from this component will be different every time the test case is run. In this case we can [mock the Date.now() method](MockFunctions.md) to return a consistent value every time the test is run: ```js Date.now = jest.fn(() => 1482363367071); @@ -291,7 +291,7 @@ Yes, all snapshot files should be committed alongside the modules they are cover ### Does snapshot testing only work with React components? -[React](TutorialReact.md) and [React Native](TutorialReactNative.md) components are a good use case for snapshot testing. However, snapshots can capture any serializable value and should be used anytime the goal is testing whether the output is correct. The Jest repository contains many examples of testing the output of Jest itself, the output of Jest's assertion library as well as log messages from various parts of the Jest codebase. See an example of [snapshotting CLI output](https://github.com/facebook/jest/blob/master/e2e/__tests__/console.test.ts) in the Jest repo. +[React](TutorialReact.md) and [React Native](TutorialReactNative.md) components are a good use case for snapshot testing. However, snapshots can capture any serializable value and should be used anytime the goal is testing whether the output is correct. The Jest repository contains many examples of testing the output of Jest itself, the output of Jest's assertion library as well as log messages from various parts of the Jest codebase. See an example of [snapshotting CLI output](https://github.com/facebook/jest/blob/main/e2e/__tests__/console.test.ts) in the Jest repo. ### What's the difference between snapshot testing and visual regression testing? diff --git a/website/versioned_docs/version-26.x/TimerMocks.md b/website/versioned_docs/version-26.x/TimerMocks.md index 75d875ea08fe..89f2066d82c3 100644 --- a/website/versioned_docs/version-26.x/TimerMocks.md +++ b/website/versioned_docs/version-26.x/TimerMocks.md @@ -160,4 +160,4 @@ it('calls the callback after 1 second via advanceTimersByTime', () => { Lastly, it may occasionally be useful in some tests to be able to clear all of the pending timers. For this, we have `jest.clearAllTimers()`. -The code for this example is available at [examples/timer](https://github.com/facebook/jest/tree/master/examples/timer). +The code for this example is available at [examples/timer](https://github.com/facebook/jest/tree/main/examples/timer). diff --git a/website/versioned_docs/version-26.x/TutorialAsync.md b/website/versioned_docs/version-26.x/TutorialAsync.md index 969d673a6532..dd8a2da77977 100644 --- a/website/versioned_docs/version-26.x/TutorialAsync.md +++ b/website/versioned_docs/version-26.x/TutorialAsync.md @@ -160,6 +160,6 @@ it('tests error with async/await and rejects', async () => { }); ``` -The code for this example is available at [examples/async](https://github.com/facebook/jest/tree/master/examples/async). +The code for this example is available at [examples/async](https://github.com/facebook/jest/tree/main/examples/async). If you'd like to test timers, like `setTimeout`, take a look at the [Timer mocks](TimerMocks.md) documentation. diff --git a/website/versioned_docs/version-26.x/TutorialReact.md b/website/versioned_docs/version-26.x/TutorialReact.md index 8fe4abc91007..d6be521ae589 100644 --- a/website/versioned_docs/version-26.x/TutorialReact.md +++ b/website/versioned_docs/version-26.x/TutorialReact.md @@ -162,7 +162,7 @@ exports[`Link changes the class when hovered 3`] = ` The next time you run the tests, the rendered output will be compared to the previously created snapshot. The snapshot should be committed along with code changes. When a snapshot test fails, you need to inspect whether it is an intended or unintended change. If the change is expected you can invoke Jest with `jest -u` to overwrite the existing snapshot. -The code for this example is available at [examples/snapshot](https://github.com/facebook/jest/tree/master/examples/snapshot). +The code for this example is available at [examples/snapshot](https://github.com/facebook/jest/tree/main/examples/snapshot). #### Snapshot Testing with Mocks, Enzyme and React 16 @@ -253,7 +253,7 @@ it('CheckboxWithLabel changes the text after click', () => { }); ``` -The code for this example is available at [examples/react-testing-library](https://github.com/facebook/jest/tree/master/examples/react-testing-library). +The code for this example is available at [examples/react-testing-library](https://github.com/facebook/jest/tree/main/examples/react-testing-library). #### Enzyme @@ -280,7 +280,7 @@ test('CheckboxWithLabel changes the text after click', () => { }); ``` -The code for this example is available at [examples/enzyme](https://github.com/facebook/jest/tree/master/examples/enzyme). +The code for this example is available at [examples/enzyme](https://github.com/facebook/jest/tree/main/examples/enzyme). ### Custom transformers diff --git a/website/versioned_docs/version-26.x/TutorialReactNative.md b/website/versioned_docs/version-26.x/TutorialReactNative.md index 5c806ff26bb9..d6c0fbf56860 100644 --- a/website/versioned_docs/version-26.x/TutorialReactNative.md +++ b/website/versioned_docs/version-26.x/TutorialReactNative.md @@ -124,7 +124,7 @@ exports[`Intro renders correctly 1`] = ` The next time you run the tests, the rendered output will be compared to the previously created snapshot. The snapshot should be committed along with code changes. When a snapshot test fails, you need to inspect whether it is an intended or unintended change. If the change is expected you can invoke Jest with `jest -u` to overwrite the existing snapshot. -The code for this example is available at [examples/react-native](https://github.com/facebook/jest/tree/master/examples/react-native). +The code for this example is available at [examples/react-native](https://github.com/facebook/jest/tree/main/examples/react-native). ## Preset configuration diff --git a/website/versioned_docs/version-26.x/TutorialjQuery.md b/website/versioned_docs/version-26.x/TutorialjQuery.md index fea33d6eb703..7532f285918f 100644 --- a/website/versioned_docs/version-26.x/TutorialjQuery.md +++ b/website/versioned_docs/version-26.x/TutorialjQuery.md @@ -65,4 +65,4 @@ The function being tested adds an event listener on the `#button` DOM element, s We are mocking `fetchCurrentUser.js` so that our test doesn't make a real network request but instead resolves to mock data locally. This ensures that our test can complete in milliseconds rather than seconds and guarantees a fast unit test iteration speed. -The code for this example is available at [examples/jquery](https://github.com/facebook/jest/tree/master/examples/jquery). +The code for this example is available at [examples/jquery](https://github.com/facebook/jest/tree/main/examples/jquery). diff --git a/website/versioned_docs/version-27.0/Configuration.md b/website/versioned_docs/version-27.0/Configuration.md index 9c2ab1e8d4d8..5c8fb451b8f7 100644 --- a/website/versioned_docs/version-27.0/Configuration.md +++ b/website/versioned_docs/version-27.0/Configuration.md @@ -234,7 +234,7 @@ _Note: You can pass additional options to the istanbul reporter using the tuple ["json", ["lcov", {"projectRoot": "../../"}]] ``` -For the additional information about the options object shape you can refer to `CoverageReporterWithOptions` type in the [type definitions](https://github.com/facebook/jest/tree/master/packages/jest-types/src/Config.ts). +For the additional information about the options object shape you can refer to `CoverageReporterWithOptions` type in the [type definitions](https://github.com/facebook/jest/tree/main/packages/jest-types/src/Config.ts). ### `coverageThreshold` \[object] @@ -765,7 +765,7 @@ class MyCustomReporter { } ``` -For the full list of methods and argument types see `Reporter` interface in [packages/jest-reporters/src/types.ts](https://github.com/facebook/jest/blob/master/packages/jest-reporters/src/types.ts) +For the full list of methods and argument types see `Reporter` interface in [packages/jest-reporters/src/types.ts](https://github.com/facebook/jest/blob/main/packages/jest-reporters/src/types.ts) ### `resetMocks` \[boolean] @@ -1032,7 +1032,7 @@ Pretty foo: Object { To make a dependency explicit instead of implicit, you can call [`expect.addSnapshotSerializer`](ExpectAPI.md#expectaddsnapshotserializerserializer) to add a module for an individual test file instead of adding its path to `snapshotSerializers` in Jest configuration. -More about serializers API can be found [here](https://github.com/facebook/jest/tree/master/packages/pretty-format/README.md#serialize). +More about serializers API can be found [here](https://github.com/facebook/jest/tree/main/packages/pretty-format/README.md#serialize). ### `testEnvironment` \[string] @@ -1055,7 +1055,7 @@ test('use jsdom in this test file', () => { You can create your own module that will be used for setting up the test environment. The module must export a class with `setup`, `teardown` and `getVmContext` methods. You can also pass variables from this module to your test suites by assigning them to `this.global` object – this will make them available in your test suites as global variables. -The class may optionally expose an asynchronous `handleTestEvent` method to bind to events fired by [`jest-circus`](https://github.com/facebook/jest/tree/master/packages/jest-circus). Normally, `jest-circus` test runner would pause until a promise returned from `handleTestEvent` gets fulfilled, **except for the next events**: `start_describe_definition`, `finish_describe_definition`, `add_hook`, `add_test` or `error` (for the up-to-date list you can look at [SyncEvent type in the types definitions](https://github.com/facebook/jest/tree/master/packages/jest-types/src/Circus.ts)). That is caused by backward compatibility reasons and `process.on('unhandledRejection', callback)` signature, but that usually should not be a problem for most of the use cases. +The class may optionally expose an asynchronous `handleTestEvent` method to bind to events fired by [`jest-circus`](https://github.com/facebook/jest/tree/main/packages/jest-circus). Normally, `jest-circus` test runner would pause until a promise returned from `handleTestEvent` gets fulfilled, **except for the next events**: `start_describe_definition`, `finish_describe_definition`, `add_hook`, `add_test` or `error` (for the up-to-date list you can look at [SyncEvent type in the types definitions](https://github.com/facebook/jest/tree/main/packages/jest-types/src/Circus.ts)). That is caused by backward compatibility reasons and `process.on('unhandledRejection', callback)` signature, but that usually should not be a problem for most of the use cases. Any docblock pragmas in test files will be passed to the environment constructor and can be used for per-test configuration. If the pragma does not have a value, it will be present in the object with its value set to an empty string. If the pragma is not present, it will not be present in the object. @@ -1250,7 +1250,7 @@ function testRunner( ): Promise; ``` -An example of such function can be found in our default [jasmine2 test runner package](https://github.com/facebook/jest/blob/master/packages/jest-jasmine2/src/index.ts). +An example of such function can be found in our default [jasmine2 test runner package](https://github.com/facebook/jest/blob/main/packages/jest-jasmine2/src/index.ts). ### `testSequencer` \[string] @@ -1310,7 +1310,7 @@ If the value is `legacy`, the old implementation will be used as implementation Default: `{"\\.[jt]sx?$": "babel-jest"}` -A map from regular expressions to paths to transformers. A transformer is a module that provides a synchronous function for transforming source files. For example, if you wanted to be able to use a new language feature in your modules or tests that aren't yet supported by node, you might plug in one of many compilers that compile a future version of JavaScript to a current one. Example: see the [examples/typescript](https://github.com/facebook/jest/blob/master/examples/typescript/package.json#L16) example or the [webpack tutorial](Webpack.md). +A map from regular expressions to paths to transformers. A transformer is a module that provides a synchronous function for transforming source files. For example, if you wanted to be able to use a new language feature in your modules or tests that aren't yet supported by node, you might plug in one of many compilers that compile a future version of JavaScript to a current one. Example: see the [examples/typescript](https://github.com/facebook/jest/blob/main/examples/typescript/package.json#L16) example or the [webpack tutorial](Webpack.md). Examples of such compilers include: @@ -1322,7 +1322,7 @@ You can pass configuration to a transformer like `{filePattern: ['path-to-transf _Note: a transformer is only run once per file unless the file has changed. During the development of a transformer it can be useful to run Jest with `--no-cache` to frequently [delete Jest's cache](Troubleshooting.md#caching-issues)._ -_Note: when adding additional code transformers, this will overwrite the default config and `babel-jest` is no longer automatically loaded. If you want to use it to compile JavaScript or Typescript, it has to be explicitly defined by adding `{"\\.[jt]sx?$": "babel-jest"}` to the transform property. See [babel-jest plugin](https://github.com/facebook/jest/tree/master/packages/babel-jest#setup)_ +_Note: when adding additional code transformers, this will overwrite the default config and `babel-jest` is no longer automatically loaded. If you want to use it to compile JavaScript or Typescript, it has to be explicitly defined by adding `{"\\.[jt]sx?$": "babel-jest"}` to the transform property. See [babel-jest plugin](https://github.com/facebook/jest/tree/main/packages/babel-jest#setup)_ A transformer must be an object with at least a `process` function, and it's also recommended to include a `getCacheKey` function. If your transformer is written in ESM you should have a default export with that object. diff --git a/website/versioned_docs/version-27.0/ExpectAPI.md b/website/versioned_docs/version-27.0/ExpectAPI.md index 9503a3f029c6..dbb2337e69ca 100644 --- a/website/versioned_docs/version-27.0/ExpectAPI.md +++ b/website/versioned_docs/version-27.0/ExpectAPI.md @@ -151,7 +151,7 @@ A boolean to let you know this matcher was called with an `expand` option. When #### `this.utils` -There are a number of helpful tools exposed on `this.utils` primarily consisting of the exports from [`jest-matcher-utils`](https://github.com/facebook/jest/tree/master/packages/jest-matcher-utils). +There are a number of helpful tools exposed on `this.utils` primarily consisting of the exports from [`jest-matcher-utils`](https://github.com/facebook/jest/tree/main/packages/jest-matcher-utils). The most useful ones are `matcherHint`, `printExpected` and `printReceived` to format the error messages nicely. For example, take a look at the implementation for the `toBe` matcher: diff --git a/website/versioned_docs/version-27.0/JestObjectAPI.md b/website/versioned_docs/version-27.0/JestObjectAPI.md index 1e31360b4985..01b177bc598f 100644 --- a/website/versioned_docs/version-27.0/JestObjectAPI.md +++ b/website/versioned_docs/version-27.0/JestObjectAPI.md @@ -672,7 +672,7 @@ jest.setTimeout(1000); // 1 second ### `jest.retryTimes()` -Runs failed tests n-times until they pass or until the max number of retries is exhausted. This only works with the default [jest-circus](https://github.com/facebook/jest/tree/master/packages/jest-circus) runner! +Runs failed tests n-times until they pass or until the max number of retries is exhausted. This only works with the default [jest-circus](https://github.com/facebook/jest/tree/main/packages/jest-circus) runner! Example in a test: diff --git a/website/versioned_docs/version-27.0/JestPlatform.md b/website/versioned_docs/version-27.0/JestPlatform.md index cfadad5dced2..2273524221cd 100644 --- a/website/versioned_docs/version-27.0/JestPlatform.md +++ b/website/versioned_docs/version-27.0/JestPlatform.md @@ -23,7 +23,7 @@ getChangedFilesForRoots(['./'], { }).then(result => console.log(result.changedFiles)); ``` -You can read more about `jest-changed-files` in the [readme file](https://github.com/facebook/jest/blob/master/packages/jest-changed-files/README.md). +You can read more about `jest-changed-files` in the [readme file](https://github.com/facebook/jest/blob/main/packages/jest-changed-files/README.md). ## jest-diff @@ -68,7 +68,7 @@ const parsed = parseWithComments(code); console.log(parsed); ``` -You can read more about `jest-docblock` in the [readme file](https://github.com/facebook/jest/blob/master/packages/jest-docblock/README.md). +You can read more about `jest-docblock` in the [readme file](https://github.com/facebook/jest/blob/main/packages/jest-docblock/README.md). ## jest-get-type @@ -115,7 +115,7 @@ const result = validate(configByUser, { console.log(result); ``` -You can read more about `jest-validate` in the [readme file](https://github.com/facebook/jest/blob/master/packages/jest-validate/README.md). +You can read more about `jest-validate` in the [readme file](https://github.com/facebook/jest/blob/main/packages/jest-validate/README.md). ## jest-worker @@ -151,7 +151,7 @@ async function main() { main(); ``` -You can read more about `jest-worker` in the [readme file](https://github.com/facebook/jest/blob/master/packages/jest-worker/README.md). +You can read more about `jest-worker` in the [readme file](https://github.com/facebook/jest/blob/main/packages/jest-worker/README.md). ## pretty-format @@ -171,4 +171,4 @@ val.array = [-0, Infinity, NaN]; console.log(prettyFormat(val)); ``` -You can read more about `pretty-format` in the [readme file](https://github.com/facebook/jest/blob/master/packages/pretty-format/README.md). +You can read more about `pretty-format` in the [readme file](https://github.com/facebook/jest/blob/main/packages/pretty-format/README.md). diff --git a/website/versioned_docs/version-27.0/ManualMocks.md b/website/versioned_docs/version-27.0/ManualMocks.md index 4732d3d10cd4..d481a5712e49 100644 --- a/website/versioned_docs/version-27.0/ManualMocks.md +++ b/website/versioned_docs/version-27.0/ManualMocks.md @@ -127,7 +127,7 @@ The example mock shown here uses [`jest.createMockFromModule`](JestObjectAPI.md# 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)`](JestObjectAPI.md#jestrequireactualmodulename) 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). +The code for this example is available at [examples/manual-mocks](https://github.com/facebook/jest/tree/main/examples/manual-mocks). ## Using with ES module imports diff --git a/website/versioned_docs/version-27.0/MockFunctionAPI.md b/website/versioned_docs/version-27.0/MockFunctionAPI.md index fb2672b08fa6..3cc228fd7880 100644 --- a/website/versioned_docs/version-27.0/MockFunctionAPI.md +++ b/website/versioned_docs/version-27.0/MockFunctionAPI.md @@ -327,7 +327,7 @@ If you are using [Create React App](https://create-react-app.dev) then the [Type Otherwise, please see our [Getting Started](GettingStarted.md#using-typescript) guide for to get setup with TypeScript. -You can see an example of using Jest with TypeScript in our [GitHub repository](https://github.com/facebook/jest/tree/master/examples/typescript). +You can see an example of using Jest with TypeScript in our [GitHub repository](https://github.com/facebook/jest/tree/main/examples/typescript). ### `jest.MockedFunction` diff --git a/website/versioned_docs/version-27.0/MoreResources.md b/website/versioned_docs/version-27.0/MoreResources.md index eae5e5120b9f..e4509d53281f 100644 --- a/website/versioned_docs/version-27.0/MoreResources.md +++ b/website/versioned_docs/version-27.0/MoreResources.md @@ -15,7 +15,7 @@ By now you should have a good idea of how Jest can help you test your applicatio ## Learn by example -You will find a number of example test cases in the [`examples`](https://github.com/facebook/jest/tree/master/examples) folder on GitHub. You can also learn from the excellent tests used by the [React](https://github.com/facebook/react/tree/master/packages/react/src/__tests__), [Relay](https://github.com/facebook/relay/tree/master/packages/react-relay/__tests__), and [React Native](https://github.com/facebook/react-native/tree/master/Libraries/Animated/src/__tests__) projects. +You will find a number of example test cases in the [`examples`](https://github.com/facebook/jest/tree/main/examples) folder on GitHub. You can also learn from the excellent tests used by the [React](https://github.com/facebook/react/tree/main/packages/react/src/__tests__), [Relay](https://github.com/facebook/relay/tree/main/packages/react-relay/__tests__), and [React Native](https://github.com/facebook/react-native/tree/main/Libraries/Animated/src/__tests__) projects. ## Join the community diff --git a/website/versioned_docs/version-27.0/SnapshotTesting.md b/website/versioned_docs/version-27.0/SnapshotTesting.md index 1d7947fc7f75..3a8e79ed9788 100644 --- a/website/versioned_docs/version-27.0/SnapshotTesting.md +++ b/website/versioned_docs/version-27.0/SnapshotTesting.md @@ -9,7 +9,7 @@ A typical snapshot test case renders a UI component, takes a snapshot, then comp ## Snapshot Testing with Jest -A similar approach can be taken when it comes to testing your React components. Instead of rendering the graphical UI, which would require building the entire app, you can use a test renderer to quickly generate a serializable value for your React tree. Consider this [example test](https://github.com/facebook/jest/blob/master/examples/snapshot/__tests__/link.react.test.js) for a [Link component](https://github.com/facebook/jest/blob/master/examples/snapshot/Link.react.js): +A similar approach can be taken when it comes to testing your React components. Instead of rendering the graphical UI, which would require building the entire app, you can use a test renderer to quickly generate a serializable value for your React tree. Consider this [example test](https://github.com/facebook/jest/blob/main/examples/snapshot/__tests__/link.react.test.js) for a [Link component](https://github.com/facebook/jest/blob/main/examples/snapshot/Link.react.js): ```tsx import React from 'react'; @@ -24,7 +24,7 @@ it('renders correctly', () => { }); ``` -The first time this test is run, Jest creates a [snapshot file](https://github.com/facebook/jest/blob/master/examples/snapshot/__tests__/__snapshots__/link.react.test.js.snap) that looks like this: +The first time this test is run, Jest creates a [snapshot file](https://github.com/facebook/jest/blob/main/examples/snapshot/__tests__/__snapshots__/link.react.test.js.snap) that looks like this: ```javascript exports[`renders correctly 1`] = ` @@ -39,7 +39,7 @@ exports[`renders correctly 1`] = ` `; ``` -The snapshot artifact should be committed alongside code changes, and reviewed as part of your code review process. Jest uses [pretty-format](https://github.com/facebook/jest/tree/master/packages/pretty-format) to make snapshots human-readable during code review. On subsequent test runs, Jest will compare the rendered output with the previous snapshot. If they match, the test will pass. If they don't match, either the test runner found a bug in your code (in the `` component in this case) that should be fixed, or the implementation has changed and the snapshot needs to be updated. +The snapshot artifact should be committed alongside code changes, and reviewed as part of your code review process. Jest uses [pretty-format](https://github.com/facebook/jest/tree/main/packages/pretty-format) to make snapshots human-readable during code review. On subsequent test runs, Jest will compare the rendered output with the previous snapshot. If they match, the test will pass. If they don't match, either the test runner found a bug in your code (in the `` component in this case) that should be fixed, or the implementation has changed and the snapshot needs to be updated. > Note: The snapshot is directly scoped to the data you render – in our example the `` component with `page` prop passed to it. This implies that even if any other file has missing props (Say, `App.js`) in the `` component, it will still pass the test as the test doesn't know the usage of `` component and it's scoped only to the `Link.react.js`. Also, Rendering the same component with different props in other snapshot tests will not affect the first one, as the tests don't know about each other. @@ -77,7 +77,7 @@ Go ahead and accept the changes by running the above command. You may also use t If you'd like to limit which snapshot test cases get re-generated, you can pass an additional `--testNamePattern` flag to re-record snapshots only for those tests that match the pattern. -You can try out this functionality by cloning the [snapshot example](https://github.com/facebook/jest/tree/master/examples/snapshot), modifying the `Link` component, and running Jest. +You can try out this functionality by cloning the [snapshot example](https://github.com/facebook/jest/tree/main/examples/snapshot), modifying the `Link` component, and running Jest. ### Interactive Snapshot Mode @@ -219,7 +219,7 @@ Commit snapshots and review them as part of your regular code review process. Th Ensure that your snapshots are readable by keeping them focused, short, and by using tools that enforce these stylistic conventions. -As mentioned previously, Jest uses [`pretty-format`](https://yarnpkg.com/en/package/pretty-format) to make snapshots human-readable, but you may find it useful to introduce additional tools, like [`eslint-plugin-jest`](https://yarnpkg.com/en/package/eslint-plugin-jest) with its [`no-large-snapshots`](https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules/no-large-snapshots.md) option, or [`snapshot-diff`](https://yarnpkg.com/en/package/snapshot-diff) with its component snapshot comparison feature, to promote committing short, focused assertions. +As mentioned previously, Jest uses [`pretty-format`](https://yarnpkg.com/en/package/pretty-format) to make snapshots human-readable, but you may find it useful to introduce additional tools, like [`eslint-plugin-jest`](https://yarnpkg.com/en/package/eslint-plugin-jest) with its [`no-large-snapshots`](https://github.com/jest-community/eslint-plugin-jest/blob/main/docs/rules/no-large-snapshots.md) option, or [`snapshot-diff`](https://yarnpkg.com/en/package/snapshot-diff) with its component snapshot comparison feature, to promote committing short, focused assertions. The goal is to make it easy to review snapshots in pull requests, and fight against the habit of regenerating snapshots when test suites fail instead of examining the root causes of their failure. @@ -227,7 +227,7 @@ The goal is to make it easy to review snapshots in pull requests, and fight agai Your tests should be deterministic. Running the same tests multiple times on a component that has not changed should produce the same results every time. You're responsible for making sure your generated snapshots do not include platform specific or other non-deterministic data. -For example, if you have a [Clock](https://github.com/facebook/jest/blob/master/examples/snapshot/Clock.react.js) component that uses `Date.now()`, the snapshot generated from this component will be different every time the test case is run. In this case we can [mock the Date.now() method](MockFunctions.md) to return a consistent value every time the test is run: +For example, if you have a [Clock](https://github.com/facebook/jest/blob/main/examples/snapshot/Clock.react.js) component that uses `Date.now()`, the snapshot generated from this component will be different every time the test case is run. In this case we can [mock the Date.now() method](MockFunctions.md) to return a consistent value every time the test is run: ```js Date.now = jest.fn(() => 1482363367071); @@ -287,7 +287,7 @@ Yes, all snapshot files should be committed alongside the modules they are cover ### Does snapshot testing only work with React components? -[React](TutorialReact.md) and [React Native](TutorialReactNative.md) components are a good use case for snapshot testing. However, snapshots can capture any serializable value and should be used anytime the goal is testing whether the output is correct. The Jest repository contains many examples of testing the output of Jest itself, the output of Jest's assertion library as well as log messages from various parts of the Jest codebase. See an example of [snapshotting CLI output](https://github.com/facebook/jest/blob/master/e2e/__tests__/console.test.ts) in the Jest repo. +[React](TutorialReact.md) and [React Native](TutorialReactNative.md) components are a good use case for snapshot testing. However, snapshots can capture any serializable value and should be used anytime the goal is testing whether the output is correct. The Jest repository contains many examples of testing the output of Jest itself, the output of Jest's assertion library as well as log messages from various parts of the Jest codebase. See an example of [snapshotting CLI output](https://github.com/facebook/jest/blob/main/e2e/__tests__/console.test.ts) in the Jest repo. ### What's the difference between snapshot testing and visual regression testing? diff --git a/website/versioned_docs/version-27.0/TimerMocks.md b/website/versioned_docs/version-27.0/TimerMocks.md index 5170e399a977..43e07ca0201f 100644 --- a/website/versioned_docs/version-27.0/TimerMocks.md +++ b/website/versioned_docs/version-27.0/TimerMocks.md @@ -175,4 +175,4 @@ it('calls the callback after 1 second via advanceTimersByTime', () => { Lastly, it may occasionally be useful in some tests to be able to clear all of the pending timers. For this, we have `jest.clearAllTimers()`. -The code for this example is available at [examples/timer](https://github.com/facebook/jest/tree/master/examples/timer). +The code for this example is available at [examples/timer](https://github.com/facebook/jest/tree/main/examples/timer). diff --git a/website/versioned_docs/version-27.0/TutorialAsync.md b/website/versioned_docs/version-27.0/TutorialAsync.md index aea53809b0cf..f9418ad6651b 100644 --- a/website/versioned_docs/version-27.0/TutorialAsync.md +++ b/website/versioned_docs/version-27.0/TutorialAsync.md @@ -160,6 +160,6 @@ it('tests error with async/await and rejects', async () => { }); ``` -The code for this example is available at [examples/async](https://github.com/facebook/jest/tree/master/examples/async). +The code for this example is available at [examples/async](https://github.com/facebook/jest/tree/main/examples/async). If you'd like to test timers, like `setTimeout`, take a look at the [Timer mocks](TimerMocks.md) documentation. diff --git a/website/versioned_docs/version-27.0/TutorialReact.md b/website/versioned_docs/version-27.0/TutorialReact.md index 838918fa8e4a..7cce1e08cf10 100644 --- a/website/versioned_docs/version-27.0/TutorialReact.md +++ b/website/versioned_docs/version-27.0/TutorialReact.md @@ -162,7 +162,7 @@ exports[`Link changes the class when hovered 3`] = ` The next time you run the tests, the rendered output will be compared to the previously created snapshot. The snapshot should be committed along with code changes. When a snapshot test fails, you need to inspect whether it is an intended or unintended change. If the change is expected you can invoke Jest with `jest -u` to overwrite the existing snapshot. -The code for this example is available at [examples/snapshot](https://github.com/facebook/jest/tree/master/examples/snapshot). +The code for this example is available at [examples/snapshot](https://github.com/facebook/jest/tree/main/examples/snapshot). #### Snapshot Testing with Mocks, Enzyme and React 16 @@ -253,7 +253,7 @@ it('CheckboxWithLabel changes the text after click', () => { }); ``` -The code for this example is available at [examples/react-testing-library](https://github.com/facebook/jest/tree/master/examples/react-testing-library). +The code for this example is available at [examples/react-testing-library](https://github.com/facebook/jest/tree/main/examples/react-testing-library). #### Enzyme @@ -280,7 +280,7 @@ test('CheckboxWithLabel changes the text after click', () => { }); ``` -The code for this example is available at [examples/enzyme](https://github.com/facebook/jest/tree/master/examples/enzyme). +The code for this example is available at [examples/enzyme](https://github.com/facebook/jest/tree/main/examples/enzyme). ### Custom transformers diff --git a/website/versioned_docs/version-27.0/TutorialReactNative.md b/website/versioned_docs/version-27.0/TutorialReactNative.md index bba83bf1c291..3bbe76e5793f 100644 --- a/website/versioned_docs/version-27.0/TutorialReactNative.md +++ b/website/versioned_docs/version-27.0/TutorialReactNative.md @@ -124,7 +124,7 @@ exports[`Intro renders correctly 1`] = ` The next time you run the tests, the rendered output will be compared to the previously created snapshot. The snapshot should be committed along with code changes. When a snapshot test fails, you need to inspect whether it is an intended or unintended change. If the change is expected you can invoke Jest with `jest -u` to overwrite the existing snapshot. -The code for this example is available at [examples/react-native](https://github.com/facebook/jest/tree/master/examples/react-native). +The code for this example is available at [examples/react-native](https://github.com/facebook/jest/tree/main/examples/react-native). ## Preset configuration diff --git a/website/versioned_docs/version-27.0/TutorialjQuery.md b/website/versioned_docs/version-27.0/TutorialjQuery.md index fea33d6eb703..7532f285918f 100644 --- a/website/versioned_docs/version-27.0/TutorialjQuery.md +++ b/website/versioned_docs/version-27.0/TutorialjQuery.md @@ -65,4 +65,4 @@ The function being tested adds an event listener on the `#button` DOM element, s We are mocking `fetchCurrentUser.js` so that our test doesn't make a real network request but instead resolves to mock data locally. This ensures that our test can complete in milliseconds rather than seconds and guarantees a fast unit test iteration speed. -The code for this example is available at [examples/jquery](https://github.com/facebook/jest/tree/master/examples/jquery). +The code for this example is available at [examples/jquery](https://github.com/facebook/jest/tree/main/examples/jquery). diff --git a/website/versioned_docs/version-27.1/Configuration.md b/website/versioned_docs/version-27.1/Configuration.md index 58c1d6133852..de70e3cdbebd 100644 --- a/website/versioned_docs/version-27.1/Configuration.md +++ b/website/versioned_docs/version-27.1/Configuration.md @@ -234,7 +234,7 @@ _Note: You can pass additional options to the istanbul reporter using the tuple ["json", ["lcov", {"projectRoot": "../../"}]] ``` -For the additional information about the options object shape you can refer to `CoverageReporterWithOptions` type in the [type definitions](https://github.com/facebook/jest/tree/master/packages/jest-types/src/Config.ts). +For the additional information about the options object shape you can refer to `CoverageReporterWithOptions` type in the [type definitions](https://github.com/facebook/jest/tree/main/packages/jest-types/src/Config.ts). ### `coverageThreshold` \[object] @@ -765,7 +765,7 @@ class MyCustomReporter { } ``` -For the full list of methods and argument types see `Reporter` interface in [packages/jest-reporters/src/types.ts](https://github.com/facebook/jest/blob/master/packages/jest-reporters/src/types.ts) +For the full list of methods and argument types see `Reporter` interface in [packages/jest-reporters/src/types.ts](https://github.com/facebook/jest/blob/main/packages/jest-reporters/src/types.ts) ### `resetMocks` \[boolean] @@ -1067,7 +1067,7 @@ Pretty foo: Object { To make a dependency explicit instead of implicit, you can call [`expect.addSnapshotSerializer`](ExpectAPI.md#expectaddsnapshotserializerserializer) to add a module for an individual test file instead of adding its path to `snapshotSerializers` in Jest configuration. -More about serializers API can be found [here](https://github.com/facebook/jest/tree/master/packages/pretty-format/README.md#serialize). +More about serializers API can be found [here](https://github.com/facebook/jest/tree/main/packages/pretty-format/README.md#serialize). ### `testEnvironment` \[string] @@ -1090,7 +1090,7 @@ test('use jsdom in this test file', () => { You can create your own module that will be used for setting up the test environment. The module must export a class with `setup`, `teardown` and `getVmContext` methods. You can also pass variables from this module to your test suites by assigning them to `this.global` object – this will make them available in your test suites as global variables. -The class may optionally expose an asynchronous `handleTestEvent` method to bind to events fired by [`jest-circus`](https://github.com/facebook/jest/tree/master/packages/jest-circus). Normally, `jest-circus` test runner would pause until a promise returned from `handleTestEvent` gets fulfilled, **except for the next events**: `start_describe_definition`, `finish_describe_definition`, `add_hook`, `add_test` or `error` (for the up-to-date list you can look at [SyncEvent type in the types definitions](https://github.com/facebook/jest/tree/master/packages/jest-types/src/Circus.ts)). That is caused by backward compatibility reasons and `process.on('unhandledRejection', callback)` signature, but that usually should not be a problem for most of the use cases. +The class may optionally expose an asynchronous `handleTestEvent` method to bind to events fired by [`jest-circus`](https://github.com/facebook/jest/tree/main/packages/jest-circus). Normally, `jest-circus` test runner would pause until a promise returned from `handleTestEvent` gets fulfilled, **except for the next events**: `start_describe_definition`, `finish_describe_definition`, `add_hook`, `add_test` or `error` (for the up-to-date list you can look at [SyncEvent type in the types definitions](https://github.com/facebook/jest/tree/main/packages/jest-types/src/Circus.ts)). That is caused by backward compatibility reasons and `process.on('unhandledRejection', callback)` signature, but that usually should not be a problem for most of the use cases. Any docblock pragmas in test files will be passed to the environment constructor and can be used for per-test configuration. If the pragma does not have a value, it will be present in the object with its value set to an empty string. If the pragma is not present, it will not be present in the object. @@ -1285,7 +1285,7 @@ function testRunner( ): Promise; ``` -An example of such function can be found in our default [jasmine2 test runner package](https://github.com/facebook/jest/blob/master/packages/jest-jasmine2/src/index.ts). +An example of such function can be found in our default [jasmine2 test runner package](https://github.com/facebook/jest/blob/main/packages/jest-jasmine2/src/index.ts). ### `testSequencer` \[string] @@ -1345,7 +1345,7 @@ If the value is `legacy`, the old implementation will be used as implementation Default: `{"\\.[jt]sx?$": "babel-jest"}` -A map from regular expressions to paths to transformers. A transformer is a module that provides a synchronous function for transforming source files. For example, if you wanted to be able to use a new language feature in your modules or tests that aren't yet supported by node, you might plug in one of many compilers that compile a future version of JavaScript to a current one. Example: see the [examples/typescript](https://github.com/facebook/jest/blob/master/examples/typescript/package.json#L16) example or the [webpack tutorial](Webpack.md). +A map from regular expressions to paths to transformers. A transformer is a module that provides a synchronous function for transforming source files. For example, if you wanted to be able to use a new language feature in your modules or tests that aren't yet supported by node, you might plug in one of many compilers that compile a future version of JavaScript to a current one. Example: see the [examples/typescript](https://github.com/facebook/jest/blob/main/examples/typescript/package.json#L16) example or the [webpack tutorial](Webpack.md). Examples of such compilers include: @@ -1357,7 +1357,7 @@ You can pass configuration to a transformer like `{filePattern: ['path-to-transf _Note: a transformer is only run once per file unless the file has changed. During the development of a transformer it can be useful to run Jest with `--no-cache` to frequently [delete Jest's cache](Troubleshooting.md#caching-issues)._ -_Note: when adding additional code transformers, this will overwrite the default config and `babel-jest` is no longer automatically loaded. If you want to use it to compile JavaScript or Typescript, it has to be explicitly defined by adding `{"\\.[jt]sx?$": "babel-jest"}` to the transform property. See [babel-jest plugin](https://github.com/facebook/jest/tree/master/packages/babel-jest#setup)_ +_Note: when adding additional code transformers, this will overwrite the default config and `babel-jest` is no longer automatically loaded. If you want to use it to compile JavaScript or Typescript, it has to be explicitly defined by adding `{"\\.[jt]sx?$": "babel-jest"}` to the transform property. See [babel-jest plugin](https://github.com/facebook/jest/tree/main/packages/babel-jest#setup)_ A transformer must be an object with at least a `process` function, and it's also recommended to include a `getCacheKey` function. If your transformer is written in ESM you should have a default export with that object. diff --git a/website/versioned_docs/version-27.1/ExpectAPI.md b/website/versioned_docs/version-27.1/ExpectAPI.md index 43a39820e975..eddf1bec562e 100644 --- a/website/versioned_docs/version-27.1/ExpectAPI.md +++ b/website/versioned_docs/version-27.1/ExpectAPI.md @@ -151,7 +151,7 @@ A boolean to let you know this matcher was called with an `expand` option. When #### `this.utils` -There are a number of helpful tools exposed on `this.utils` primarily consisting of the exports from [`jest-matcher-utils`](https://github.com/facebook/jest/tree/master/packages/jest-matcher-utils). +There are a number of helpful tools exposed on `this.utils` primarily consisting of the exports from [`jest-matcher-utils`](https://github.com/facebook/jest/tree/main/packages/jest-matcher-utils). The most useful ones are `matcherHint`, `printExpected` and `printReceived` to format the error messages nicely. For example, take a look at the implementation for the `toBe` matcher: diff --git a/website/versioned_docs/version-27.1/JestObjectAPI.md b/website/versioned_docs/version-27.1/JestObjectAPI.md index 1e31360b4985..01b177bc598f 100644 --- a/website/versioned_docs/version-27.1/JestObjectAPI.md +++ b/website/versioned_docs/version-27.1/JestObjectAPI.md @@ -672,7 +672,7 @@ jest.setTimeout(1000); // 1 second ### `jest.retryTimes()` -Runs failed tests n-times until they pass or until the max number of retries is exhausted. This only works with the default [jest-circus](https://github.com/facebook/jest/tree/master/packages/jest-circus) runner! +Runs failed tests n-times until they pass or until the max number of retries is exhausted. This only works with the default [jest-circus](https://github.com/facebook/jest/tree/main/packages/jest-circus) runner! Example in a test: diff --git a/website/versioned_docs/version-27.1/JestPlatform.md b/website/versioned_docs/version-27.1/JestPlatform.md index cfadad5dced2..2273524221cd 100644 --- a/website/versioned_docs/version-27.1/JestPlatform.md +++ b/website/versioned_docs/version-27.1/JestPlatform.md @@ -23,7 +23,7 @@ getChangedFilesForRoots(['./'], { }).then(result => console.log(result.changedFiles)); ``` -You can read more about `jest-changed-files` in the [readme file](https://github.com/facebook/jest/blob/master/packages/jest-changed-files/README.md). +You can read more about `jest-changed-files` in the [readme file](https://github.com/facebook/jest/blob/main/packages/jest-changed-files/README.md). ## jest-diff @@ -68,7 +68,7 @@ const parsed = parseWithComments(code); console.log(parsed); ``` -You can read more about `jest-docblock` in the [readme file](https://github.com/facebook/jest/blob/master/packages/jest-docblock/README.md). +You can read more about `jest-docblock` in the [readme file](https://github.com/facebook/jest/blob/main/packages/jest-docblock/README.md). ## jest-get-type @@ -115,7 +115,7 @@ const result = validate(configByUser, { console.log(result); ``` -You can read more about `jest-validate` in the [readme file](https://github.com/facebook/jest/blob/master/packages/jest-validate/README.md). +You can read more about `jest-validate` in the [readme file](https://github.com/facebook/jest/blob/main/packages/jest-validate/README.md). ## jest-worker @@ -151,7 +151,7 @@ async function main() { main(); ``` -You can read more about `jest-worker` in the [readme file](https://github.com/facebook/jest/blob/master/packages/jest-worker/README.md). +You can read more about `jest-worker` in the [readme file](https://github.com/facebook/jest/blob/main/packages/jest-worker/README.md). ## pretty-format @@ -171,4 +171,4 @@ val.array = [-0, Infinity, NaN]; console.log(prettyFormat(val)); ``` -You can read more about `pretty-format` in the [readme file](https://github.com/facebook/jest/blob/master/packages/pretty-format/README.md). +You can read more about `pretty-format` in the [readme file](https://github.com/facebook/jest/blob/main/packages/pretty-format/README.md). diff --git a/website/versioned_docs/version-27.1/ManualMocks.md b/website/versioned_docs/version-27.1/ManualMocks.md index 4732d3d10cd4..d481a5712e49 100644 --- a/website/versioned_docs/version-27.1/ManualMocks.md +++ b/website/versioned_docs/version-27.1/ManualMocks.md @@ -127,7 +127,7 @@ The example mock shown here uses [`jest.createMockFromModule`](JestObjectAPI.md# 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)`](JestObjectAPI.md#jestrequireactualmodulename) 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). +The code for this example is available at [examples/manual-mocks](https://github.com/facebook/jest/tree/main/examples/manual-mocks). ## Using with ES module imports diff --git a/website/versioned_docs/version-27.1/MockFunctionAPI.md b/website/versioned_docs/version-27.1/MockFunctionAPI.md index fb2672b08fa6..3cc228fd7880 100644 --- a/website/versioned_docs/version-27.1/MockFunctionAPI.md +++ b/website/versioned_docs/version-27.1/MockFunctionAPI.md @@ -327,7 +327,7 @@ If you are using [Create React App](https://create-react-app.dev) then the [Type Otherwise, please see our [Getting Started](GettingStarted.md#using-typescript) guide for to get setup with TypeScript. -You can see an example of using Jest with TypeScript in our [GitHub repository](https://github.com/facebook/jest/tree/master/examples/typescript). +You can see an example of using Jest with TypeScript in our [GitHub repository](https://github.com/facebook/jest/tree/main/examples/typescript). ### `jest.MockedFunction` diff --git a/website/versioned_docs/version-27.1/MoreResources.md b/website/versioned_docs/version-27.1/MoreResources.md index eae5e5120b9f..e4509d53281f 100644 --- a/website/versioned_docs/version-27.1/MoreResources.md +++ b/website/versioned_docs/version-27.1/MoreResources.md @@ -15,7 +15,7 @@ By now you should have a good idea of how Jest can help you test your applicatio ## Learn by example -You will find a number of example test cases in the [`examples`](https://github.com/facebook/jest/tree/master/examples) folder on GitHub. You can also learn from the excellent tests used by the [React](https://github.com/facebook/react/tree/master/packages/react/src/__tests__), [Relay](https://github.com/facebook/relay/tree/master/packages/react-relay/__tests__), and [React Native](https://github.com/facebook/react-native/tree/master/Libraries/Animated/src/__tests__) projects. +You will find a number of example test cases in the [`examples`](https://github.com/facebook/jest/tree/main/examples) folder on GitHub. You can also learn from the excellent tests used by the [React](https://github.com/facebook/react/tree/main/packages/react/src/__tests__), [Relay](https://github.com/facebook/relay/tree/main/packages/react-relay/__tests__), and [React Native](https://github.com/facebook/react-native/tree/main/Libraries/Animated/src/__tests__) projects. ## Join the community diff --git a/website/versioned_docs/version-27.1/SnapshotTesting.md b/website/versioned_docs/version-27.1/SnapshotTesting.md index 1d7947fc7f75..3a8e79ed9788 100644 --- a/website/versioned_docs/version-27.1/SnapshotTesting.md +++ b/website/versioned_docs/version-27.1/SnapshotTesting.md @@ -9,7 +9,7 @@ A typical snapshot test case renders a UI component, takes a snapshot, then comp ## Snapshot Testing with Jest -A similar approach can be taken when it comes to testing your React components. Instead of rendering the graphical UI, which would require building the entire app, you can use a test renderer to quickly generate a serializable value for your React tree. Consider this [example test](https://github.com/facebook/jest/blob/master/examples/snapshot/__tests__/link.react.test.js) for a [Link component](https://github.com/facebook/jest/blob/master/examples/snapshot/Link.react.js): +A similar approach can be taken when it comes to testing your React components. Instead of rendering the graphical UI, which would require building the entire app, you can use a test renderer to quickly generate a serializable value for your React tree. Consider this [example test](https://github.com/facebook/jest/blob/main/examples/snapshot/__tests__/link.react.test.js) for a [Link component](https://github.com/facebook/jest/blob/main/examples/snapshot/Link.react.js): ```tsx import React from 'react'; @@ -24,7 +24,7 @@ it('renders correctly', () => { }); ``` -The first time this test is run, Jest creates a [snapshot file](https://github.com/facebook/jest/blob/master/examples/snapshot/__tests__/__snapshots__/link.react.test.js.snap) that looks like this: +The first time this test is run, Jest creates a [snapshot file](https://github.com/facebook/jest/blob/main/examples/snapshot/__tests__/__snapshots__/link.react.test.js.snap) that looks like this: ```javascript exports[`renders correctly 1`] = ` @@ -39,7 +39,7 @@ exports[`renders correctly 1`] = ` `; ``` -The snapshot artifact should be committed alongside code changes, and reviewed as part of your code review process. Jest uses [pretty-format](https://github.com/facebook/jest/tree/master/packages/pretty-format) to make snapshots human-readable during code review. On subsequent test runs, Jest will compare the rendered output with the previous snapshot. If they match, the test will pass. If they don't match, either the test runner found a bug in your code (in the `` component in this case) that should be fixed, or the implementation has changed and the snapshot needs to be updated. +The snapshot artifact should be committed alongside code changes, and reviewed as part of your code review process. Jest uses [pretty-format](https://github.com/facebook/jest/tree/main/packages/pretty-format) to make snapshots human-readable during code review. On subsequent test runs, Jest will compare the rendered output with the previous snapshot. If they match, the test will pass. If they don't match, either the test runner found a bug in your code (in the `` component in this case) that should be fixed, or the implementation has changed and the snapshot needs to be updated. > Note: The snapshot is directly scoped to the data you render – in our example the `` component with `page` prop passed to it. This implies that even if any other file has missing props (Say, `App.js`) in the `` component, it will still pass the test as the test doesn't know the usage of `` component and it's scoped only to the `Link.react.js`. Also, Rendering the same component with different props in other snapshot tests will not affect the first one, as the tests don't know about each other. @@ -77,7 +77,7 @@ Go ahead and accept the changes by running the above command. You may also use t If you'd like to limit which snapshot test cases get re-generated, you can pass an additional `--testNamePattern` flag to re-record snapshots only for those tests that match the pattern. -You can try out this functionality by cloning the [snapshot example](https://github.com/facebook/jest/tree/master/examples/snapshot), modifying the `Link` component, and running Jest. +You can try out this functionality by cloning the [snapshot example](https://github.com/facebook/jest/tree/main/examples/snapshot), modifying the `Link` component, and running Jest. ### Interactive Snapshot Mode @@ -219,7 +219,7 @@ Commit snapshots and review them as part of your regular code review process. Th Ensure that your snapshots are readable by keeping them focused, short, and by using tools that enforce these stylistic conventions. -As mentioned previously, Jest uses [`pretty-format`](https://yarnpkg.com/en/package/pretty-format) to make snapshots human-readable, but you may find it useful to introduce additional tools, like [`eslint-plugin-jest`](https://yarnpkg.com/en/package/eslint-plugin-jest) with its [`no-large-snapshots`](https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules/no-large-snapshots.md) option, or [`snapshot-diff`](https://yarnpkg.com/en/package/snapshot-diff) with its component snapshot comparison feature, to promote committing short, focused assertions. +As mentioned previously, Jest uses [`pretty-format`](https://yarnpkg.com/en/package/pretty-format) to make snapshots human-readable, but you may find it useful to introduce additional tools, like [`eslint-plugin-jest`](https://yarnpkg.com/en/package/eslint-plugin-jest) with its [`no-large-snapshots`](https://github.com/jest-community/eslint-plugin-jest/blob/main/docs/rules/no-large-snapshots.md) option, or [`snapshot-diff`](https://yarnpkg.com/en/package/snapshot-diff) with its component snapshot comparison feature, to promote committing short, focused assertions. The goal is to make it easy to review snapshots in pull requests, and fight against the habit of regenerating snapshots when test suites fail instead of examining the root causes of their failure. @@ -227,7 +227,7 @@ The goal is to make it easy to review snapshots in pull requests, and fight agai Your tests should be deterministic. Running the same tests multiple times on a component that has not changed should produce the same results every time. You're responsible for making sure your generated snapshots do not include platform specific or other non-deterministic data. -For example, if you have a [Clock](https://github.com/facebook/jest/blob/master/examples/snapshot/Clock.react.js) component that uses `Date.now()`, the snapshot generated from this component will be different every time the test case is run. In this case we can [mock the Date.now() method](MockFunctions.md) to return a consistent value every time the test is run: +For example, if you have a [Clock](https://github.com/facebook/jest/blob/main/examples/snapshot/Clock.react.js) component that uses `Date.now()`, the snapshot generated from this component will be different every time the test case is run. In this case we can [mock the Date.now() method](MockFunctions.md) to return a consistent value every time the test is run: ```js Date.now = jest.fn(() => 1482363367071); @@ -287,7 +287,7 @@ Yes, all snapshot files should be committed alongside the modules they are cover ### Does snapshot testing only work with React components? -[React](TutorialReact.md) and [React Native](TutorialReactNative.md) components are a good use case for snapshot testing. However, snapshots can capture any serializable value and should be used anytime the goal is testing whether the output is correct. The Jest repository contains many examples of testing the output of Jest itself, the output of Jest's assertion library as well as log messages from various parts of the Jest codebase. See an example of [snapshotting CLI output](https://github.com/facebook/jest/blob/master/e2e/__tests__/console.test.ts) in the Jest repo. +[React](TutorialReact.md) and [React Native](TutorialReactNative.md) components are a good use case for snapshot testing. However, snapshots can capture any serializable value and should be used anytime the goal is testing whether the output is correct. The Jest repository contains many examples of testing the output of Jest itself, the output of Jest's assertion library as well as log messages from various parts of the Jest codebase. See an example of [snapshotting CLI output](https://github.com/facebook/jest/blob/main/e2e/__tests__/console.test.ts) in the Jest repo. ### What's the difference between snapshot testing and visual regression testing? diff --git a/website/versioned_docs/version-27.1/TimerMocks.md b/website/versioned_docs/version-27.1/TimerMocks.md index 5170e399a977..43e07ca0201f 100644 --- a/website/versioned_docs/version-27.1/TimerMocks.md +++ b/website/versioned_docs/version-27.1/TimerMocks.md @@ -175,4 +175,4 @@ it('calls the callback after 1 second via advanceTimersByTime', () => { Lastly, it may occasionally be useful in some tests to be able to clear all of the pending timers. For this, we have `jest.clearAllTimers()`. -The code for this example is available at [examples/timer](https://github.com/facebook/jest/tree/master/examples/timer). +The code for this example is available at [examples/timer](https://github.com/facebook/jest/tree/main/examples/timer). diff --git a/website/versioned_docs/version-27.1/TutorialAsync.md b/website/versioned_docs/version-27.1/TutorialAsync.md index aea53809b0cf..f9418ad6651b 100644 --- a/website/versioned_docs/version-27.1/TutorialAsync.md +++ b/website/versioned_docs/version-27.1/TutorialAsync.md @@ -160,6 +160,6 @@ it('tests error with async/await and rejects', async () => { }); ``` -The code for this example is available at [examples/async](https://github.com/facebook/jest/tree/master/examples/async). +The code for this example is available at [examples/async](https://github.com/facebook/jest/tree/main/examples/async). If you'd like to test timers, like `setTimeout`, take a look at the [Timer mocks](TimerMocks.md) documentation. diff --git a/website/versioned_docs/version-27.1/TutorialReact.md b/website/versioned_docs/version-27.1/TutorialReact.md index 838918fa8e4a..7cce1e08cf10 100644 --- a/website/versioned_docs/version-27.1/TutorialReact.md +++ b/website/versioned_docs/version-27.1/TutorialReact.md @@ -162,7 +162,7 @@ exports[`Link changes the class when hovered 3`] = ` The next time you run the tests, the rendered output will be compared to the previously created snapshot. The snapshot should be committed along with code changes. When a snapshot test fails, you need to inspect whether it is an intended or unintended change. If the change is expected you can invoke Jest with `jest -u` to overwrite the existing snapshot. -The code for this example is available at [examples/snapshot](https://github.com/facebook/jest/tree/master/examples/snapshot). +The code for this example is available at [examples/snapshot](https://github.com/facebook/jest/tree/main/examples/snapshot). #### Snapshot Testing with Mocks, Enzyme and React 16 @@ -253,7 +253,7 @@ it('CheckboxWithLabel changes the text after click', () => { }); ``` -The code for this example is available at [examples/react-testing-library](https://github.com/facebook/jest/tree/master/examples/react-testing-library). +The code for this example is available at [examples/react-testing-library](https://github.com/facebook/jest/tree/main/examples/react-testing-library). #### Enzyme @@ -280,7 +280,7 @@ test('CheckboxWithLabel changes the text after click', () => { }); ``` -The code for this example is available at [examples/enzyme](https://github.com/facebook/jest/tree/master/examples/enzyme). +The code for this example is available at [examples/enzyme](https://github.com/facebook/jest/tree/main/examples/enzyme). ### Custom transformers diff --git a/website/versioned_docs/version-27.1/TutorialReactNative.md b/website/versioned_docs/version-27.1/TutorialReactNative.md index bba83bf1c291..3bbe76e5793f 100644 --- a/website/versioned_docs/version-27.1/TutorialReactNative.md +++ b/website/versioned_docs/version-27.1/TutorialReactNative.md @@ -124,7 +124,7 @@ exports[`Intro renders correctly 1`] = ` The next time you run the tests, the rendered output will be compared to the previously created snapshot. The snapshot should be committed along with code changes. When a snapshot test fails, you need to inspect whether it is an intended or unintended change. If the change is expected you can invoke Jest with `jest -u` to overwrite the existing snapshot. -The code for this example is available at [examples/react-native](https://github.com/facebook/jest/tree/master/examples/react-native). +The code for this example is available at [examples/react-native](https://github.com/facebook/jest/tree/main/examples/react-native). ## Preset configuration diff --git a/website/versioned_docs/version-27.1/TutorialjQuery.md b/website/versioned_docs/version-27.1/TutorialjQuery.md index fea33d6eb703..7532f285918f 100644 --- a/website/versioned_docs/version-27.1/TutorialjQuery.md +++ b/website/versioned_docs/version-27.1/TutorialjQuery.md @@ -65,4 +65,4 @@ The function being tested adds an event listener on the `#button` DOM element, s We are mocking `fetchCurrentUser.js` so that our test doesn't make a real network request but instead resolves to mock data locally. This ensures that our test can complete in milliseconds rather than seconds and guarantees a fast unit test iteration speed. -The code for this example is available at [examples/jquery](https://github.com/facebook/jest/tree/master/examples/jquery). +The code for this example is available at [examples/jquery](https://github.com/facebook/jest/tree/main/examples/jquery). diff --git a/website/videos.json b/website/videos.json index c8510184a34d..bee8bfc040f2 100644 --- a/website/videos.json +++ b/website/videos.json @@ -1,5 +1,5 @@ { - "editUrl": "https://github.com/facebook/jest/edit/master/website/videos.json", + "editUrl": "https://github.com/facebook/jest/edit/main/website/videos.json", "videos": [ { "title": "Rogelio Guzman - Jest Snapshots and Beyond - React Conf 2017",
mastermain Documentation