Skip to content

Commit 27a8077

Browse files
authored
Revamped Jest Docs and Website
New look and feel. Updated all tutorials, docs, guides with latest best practices. * Cleaned up API Reference docs (#2422) * Reorganized Sidebar Navigation * New Introduction Section (#2425) * Simplified Getting Started introduction * Break up API Reference into multiple docs, separate from Guides (#2388) * Support is now Help (#2370) * Add "Snapshot Testing", "Testing Asynchronous Code" & "Setup and Teardown" docs (#2419, #2406) * Create Jest user showcase (#2369) * New blog post announcing refreshed documentation (#2522) * Truncate blog posts in blog index * New homepage hero (#2662) * New mobile nav (#2664) * Add standard FB Open Source Footer (#2660) * Add RedirectLayout to prevent broken links (#2700) * Refreshed Homepage and Colors across site (#2699) * Deploy Jest website via CircleCI
1 parent e4718cb commit 27a8077

114 files changed

Lines changed: 4317 additions & 2732 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.eslintignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,8 @@ examples/react-native
77
flow-typed/**
88
packages/*/build/**
99
types/**
10-
website/
10+
website/build
11+
website/node_modules
12+
website/core/metadata*.js
13+
website/src/jest/docs
14+
website/src/jest/blog

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
/packages/*/node_modules/
1313
/website/build
1414
/website/node_modules
15+
/website/core/metadata*.js
16+
/website/src/jest/docs
17+
/website/src/jest/blog
18+
/integration_tests/transform/*/coverage
19+
/integration_tests/transform/*/node_modules
20+
/integration_tests/*/node_modules
21+
npm-debug.log
1522
coverage
1623
lerna-debug.log
1724
npm-debug.log*

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ Facebook has a [bounty program](https://www.facebook.com/whitehat/) for the safe
8383
* 2 spaces for indentation (no tabs).
8484
* 80 character line length strongly preferred.
8585
* Prefer `'` over `"`.
86-
* ES2015 syntax when possible.
86+
* ES6 syntax when possible.
8787
* `'use strict';`.
8888
* Use [Flow types](http://flowtype.org/).
8989
* Use semicolons;

README.md

Lines changed: 58 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -12,98 +12,105 @@ Painless JavaScript Testing
1212
## Getting Started
1313

1414
<generated_getting_started_start />
15-
Before you install Jest, you can try out a real version of Jest through [repl.it](https://repl.it). Just edit your test and hit the run button!
16-
<iframe class="jest-repl" src="https://repl.it/languages/jest?lite=true"></iframe>
15+
Install Jest using `npm`:
1716

18-
Install Jest with `yarn` or `npm` by running `yarn add -D jest` or `npm install --save-dev jest`. Let's get started by writing a test for a hypothetical `sum.js` file:
17+
```
18+
npm install --save-dev jest
19+
```
20+
21+
Let's get started by writing a test for a hypothetical function that adds two numbers. First, create a `sum.js` file:
1922

2023
```javascript
21-
module.exports = (a, b) => a + b;
24+
function sum(a, b) {
25+
return a + b;
26+
}
27+
module.exports = sum;
2228
```
2329

24-
Create a directory `__tests__/` with a file `sum-test.js` or name it `sum.test.js` or `sum.spec.js` and put it anywhere in your project:
30+
Then, create a file named `sum.test.js`. This will contain our actual test:
2531

2632
```javascript
33+
const sum = require('./sum');
34+
2735
test('adds 1 + 2 to equal 3', () => {
28-
const sum = require('../sum');
2936
expect(sum(1, 2)).toBe(3);
3037
});
3138
```
3239

33-
Add the following to your `package.json`:
40+
Add the following section to your `package.json`:
3441

3542
```js
3643
"scripts": {
3744
"test": "jest"
3845
}
3946
```
4047

41-
Run `yarn test` and Jest will print this message: `PASS __tests__/sum-test.js`. You just successfully wrote your first test using Jest!
48+
Finally, run `npm test` and Jest will print this message:
4249

43-
**You are ready to use Jest! Here are some more resources to help you get started:**
50+
```
51+
PASS ./sum.test.js
52+
✓ adds 1 + 2 to equal 3 (5ms)
53+
```
54+
55+
**You just successfully wrote your first test using Jest!**
56+
57+
This test used `expect` and `toBe` to test that two values were exactly identical. To learn about the other things that Jest can test, see [Using Matchers](https://facebook.github.io/jest/docs/using-matchers.html).
4458

45-
* Read the [API Documentation](https://facebook.github.io/jest/docs/api.html) to learn about all available assertions, ways of writing tests and Jest specific APIs.
46-
* [Jest Configuration](https://facebook.github.io/jest/docs/configuration.html).
47-
* [Example Code](https://github.com/facebook/jest/tree/master/examples/getting_started).
48-
* [Migration from other test runners](https://facebook.github.io/jest/docs/migration-guide.html).
49-
* Introductory guide at [Plotly Academy](https://academy.plot.ly/react/6-testing) that walks you through testing a React and Redux application.
50-
* The [React](https://github.com/facebook/react/tree/master/src/renderers/shared/stack/reconciler/__tests__), [Relay](https://github.com/facebook/relay/tree/master/src/container/__tests__) and [react-native](https://github.com/facebook/react-native/tree/master/Libraries/Animated/src/__tests__) repositories have excellent examples of tests written by Facebook engineers.
59+
<!--truncate-->
5160

52-
**...or watch a video to get started with Jest:**
53-
<div class="video">
54-
<iframe src="https://fast.wistia.net/embed/iframe/78j73pyz17"></iframe>
55-
</div>
56-
<div class="video-shoutout">
57-
<a href="https://egghead.io/lessons/javascript-test-javascript-with-jest">Video</a> by <a href="https://twitter.com/kentcdodds">Kent C. Dodds</a> hosted by <a href="https://egghead.io">Egghead</a>.
58-
</div>
61+
## Additional Configuration
5962

60-
### Babel Integration
63+
### Using Babel
6164

62-
If you'd like to use [Babel](http://babeljs.io/), it can easily be enabled: `yarn add -D babel-jest babel-polyfill`.
65+
To use [Babel](http://babeljs.io/), install the `babel-jest` and `babel-polyfill` packages:
6366

64-
Don't forget to add a [`.babelrc`](https://babeljs.io/docs/usage/babelrc/) file in your project's root folder. For example, if you are using ES2015 and [React.js](https://facebook.github.io/react/) with the [`babel-preset-es2015`](https://babeljs.io/docs/plugins/preset-es2015/) and [`babel-preset-react`](https://babeljs.io/docs/plugins/preset-react/) presets:
67+
```
68+
npm install --save-dev babel-jest babel-polyfill
69+
```
70+
71+
Don't forget to add a [`.babelrc`](https://babeljs.io/docs/usage/babelrc/) file in your project's root folder. For example, if you are using ES6 and [React.js](https://facebook.github.io/react/) with the [`babel-preset-es2015`](https://babeljs.io/docs/plugins/preset-es2015/) and [`babel-preset-react`](https://babeljs.io/docs/plugins/preset-react/) presets:
6572

6673
```js
6774
{
6875
"presets": ["es2015", "react"]
6976
}
7077
```
7178

72-
You are now set up to use all ES2015 features and React specific syntax.
79+
You are now set up to use all ES6 features and React specific syntax.
7380

74-
*Note: If you are using a more complicated Babel configuration, using Babel's `env` option,
81+
> Note: If you are using a more complicated Babel configuration, using Babel's `env` option,
7582
keep in mind that Jest will automatically define `NODE_ENV` as `test`.
76-
It will not use `development` section like Babel does by default when no `NODE_ENV` is set.*
83+
It will not use `development` section like Babel does by default when no `NODE_ENV` is set.
7784

78-
### React, React Native and Snapshot Testing
85+
### Using webpack
7986

80-
Check out the [React tutorial](https://facebook.github.io/jest/docs/tutorial-react.html) and the [React Native tutorial](https://facebook.github.io/jest/docs/tutorial-react-native.html) to get started with React or React Native codebases. You can use React's test renderer (`yarn add -D react-test-renderer`) to capture snapshots with Jest's snapshot feature and the `toMatchSnapshot` matcher:
87+
Jest can be used in projects that use [webpack](https://webpack.github.io/) to manage assets, styles, and compilation. webpack does offer some unique challenges over other tools. Refer to the [webpack guide](https://facebook.github.io/jest/docs/webpack.html) to get started.
8188

82-
```js
83-
import renderer from 'react-test-renderer';
84-
test('Link renders correctly', () => {
85-
const tree = renderer.create(
86-
<Link page="http://www.facebook.com">Facebook</Link>
87-
).toJSON();
88-
expect(tree).toMatchSnapshot();
89-
});
90-
```
89+
### Using TypeScript
9190

92-
and it will produce a snapshot like this:
91+
To use TypeScript in your tests, install the `ts-jest` package:
9392

94-
```js
95-
exports[`Link renders correctly 1`] = `
96-
<a
97-
className="normal"
98-
href="http://www.facebook.com"
99-
onMouseEnter={[Function]}
100-
onMouseLeave={[Function]}>
101-
Facebook
102-
</a>
103-
`;
10493
```
94+
npm install --save-dev test-jest
95+
```
96+
97+
then modify your `package.json` so the `jest` section looks something like:
10598

106-
On subsequent test runs, Jest will compare the stored snapshot with the rendered output and highlight differences. If there are differences, Jest will ask you to fix your mistake and can be re-run with `-u` or `--updateSnapshot` to update an outdated snapshot.
99+
```json
100+
{
101+
"jest": {
102+
"transform": {
103+
".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
104+
},
105+
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
106+
"moduleFileExtensions": [
107+
"ts",
108+
"tsx",
109+
"js"
110+
]
111+
}
112+
}
113+
```
107114
<generated_getting_started_end />
108115

109116
## API & Configuration

blog/2016-09-01-jest-15.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ We spent the past year making Jest [faster](http://facebook.github.io/jest/blog/
99

1010
The most important change to talk about is a set of [new defaults](https://github.com/facebook/jest/pull/1511). If you are an existing Jest user you will very likely need to update your configuration for Jest 15. In most cases it will simplify your setup and Jest will provide useful error messages during the upgrade. All of the new defaults can be disabled to suit your needs, but we still consider the disabled features critical for Jest in certain situations and will continue to use and support them at Facebook long-term. Our [API documentation](https://facebook.github.io/jest/docs/api.html) was also completely rewritten to reflect these changes. [This pull request for React](https://github.com/facebook/react/pull/7625/files) highlights some of the changes necessary for existing projects.
1111

12+
<!--truncate-->
13+
1214
## New CLI error messages and summaries
1315

1416
As part of our effort to remove Jasmine incrementally within Jest, replacing all Jasmine matchers was almost completed. A lot of time was spent tweaking every error message for every matcher to give the best signal to users when a test is failing – the time when Jest should provide the most value to you. In addition to printing the expected and received values, a diff is printed for the `toBe` and `toEqual` matchers to help spot mistakes. More colors were added and relevant files from stack traces are highlighted more prominently.

blog/2016-10-03-jest-16.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ authorFBID: 100000023028168
77

88
It's been one month since the last major release and we've made significant improvements to Jest since. In this major release we are updating the snapshot format we are using which will likely require snapshots to be updated when upgrading Jest. We don't make these changes lightly and don't expect this to happen often but we think it is necessary to improve the format from time to time.
99

10+
<!--truncate-->
11+
1012
## Upgraded CLI
1113

1214
![reporter](/jest/img/blog/16-reporter.gif)

blog/2016-12-15-2016-in-jest.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ authorFBID: 100000023028168
77

88
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).
99

10+
<!--truncate-->
11+
1012
The newly created [react-test-renderer](https://www.npmjs.com/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).
1113

1214
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.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
title: A Great Developer Experience
3+
author: Héctor Ramos
4+
authorURL: http://twitter.com/hectorramos
5+
authorFBID: 121800083
6+
---
7+
8+
We strongly believe that great documentation is crucial to providing a great developer experience. The docs should be clear, concise, and useful to new users and veterans alike. With that in mind, we recently took some time to overhaul the Jest website.
9+
10+
<!--truncate-->
11+
12+
## Improved Docs
13+
14+
One of the changes you'll notice upon visiting our docs is the updated sidebar. The documentation is now divided into three main areas: an introduction to Jest, advanced guides to Jest's features, and a comprehensive API reference.
15+
16+
The **Introduction** section will guide you from installing Jest and writing your first case, to using Jest's matchers and testing async code. If you're new to Jest or need a quick refresher, these docs should get you up to speed in no time. If you've used Jest before and only need a quick reference on how it's installed, you need to go no further than the [Getting Started](/jest/docs/getting-started.html) guide.
17+
18+
Once you feel comfortable using Jest, proceed to the advanced **Guides** section. The new [Snapshot Testing guide](/jest/docs/snapshot-testing.html) covers everything you need to know about creating and maintaining snapshot test cases.
19+
20+
Finally, we've completely overhauled our API reference docs. You can now find detailed information on all of Jest's [Globals](/jest/docs/api.html), [matchers](/jest/docs/expect.html), and [every flag](/jest/docs/cli.html) supported by the `jest` CLI.
21+
22+
## Who's Using Jest?
23+
24+
We have created a [showcase of users](/jest/users.html) to highlight some of the companies that are using Jest. We're thankful to all of these companies for using Jest to test their websites, mobile apps, and APIs. If you're using Jest, check out the guidelines on GitHub and send us a pull request!
25+
26+
<div class="miniShowcaseSection">
27+
<div class="logos">
28+
<img src="/jest/img/logos/twitter.png" title="Twitter"/>
29+
<img src="/jest/img/logos/pinterest.png" title="Pinterest"/>
30+
<img src="/jest/img/logos/paypal.png" title="PayPal"/>
31+
<img src="/jest/img/logos/ibm.png" title="IBM"/>
32+
<img src="/jest/img/logos/spotify.png" title="Spotify"/>
33+
</div>
34+
</div>
35+
36+
## Jest in the Browser
37+
38+
As highlighted [last month](/jest/blog/2016/12/15/2016-in-jest.html), it is now possible to use Jest directly in the browser using [repl.it](https://repl.it/languages/jest). If you want to try out Jest before installing it, you can easily do so below or directly from the Jest homepage. Go ahead and give it a try!
39+
40+
<iframe class="jest-repl" src="https://repl.it/languages/jest?lite=true"></iframe>
41+
42+
## Get Involved
43+
44+
This is just the start. Go ahead and take a look at the docs, and don't hesitate to send any feedback our way. If you find a mistake in the docs or you just want to let us know what needs to be documented better, please tweet at us at [@fbjest](https://twitter.com/fbjest), [open an issue on GitHub](https://github.com/facebook/jest/issues), or send us a PR by clicking "Edit on GitHub" at the top of the doc.
45+
46+
We're really excited for the year ahead and can't wait to hear from you!

0 commit comments

Comments
 (0)