Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new globals to docs #1686

Merged
merged 1 commit into from
Sep 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 49 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ Don't forget to add a [`.babelrc`](https://babeljs.io/docs/usage/babelrc/) file

You are now set up to use all ES2015 features and React specific syntax.

If you are using a more complicated Babel configuration, using Babel's `env` option,
keep in mind that Jest will automatically define `NODE_ENV` as `test`.
It will not use `development` section like Babel does by default when no `NODE_ENV` is set.

### React, React-Native and Snapshot Testing

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.
Expand Down Expand Up @@ -207,14 +211,18 @@ In your test files, Jest puts each of these methods and objects into the global

- `afterEach(fn)`
- `beforeEach(fn)`
- `afterAll(fn)`
- `beforeAll(fn)`
- [`describe(name, fn)`](https://facebook.github.io/jest/docs/api.html#basic-testing)
- [`expect(value)`](https://facebook.github.io/jest/docs/api.html#expect-value)
- [`it(name, fn)`](https://facebook.github.io/jest/docs/api.html#basic-testing)
- [`it.only(name, fn)`](https://facebook.github.io/jest/docs/api.html#basic-testing)
- [`it.skip(name, fn)`](https://facebook.github.io/jest/docs/api.html#basic-testing)
- `fit(name, fn)` executes only this test. Useful when investigating a failure
- [`jest`](https://facebook.github.io/jest/docs/api.html#the-jest-object)
- [`require.requireActual(moduleName)`](https://facebook.github.io/jest/docs/api.html#require-requireactual-modulename)
- [`require.requireMock(moduleName)`](https://facebook.github.io/jest/docs/api.html#require-requiremock-modulename)
- `test(name, fn)` is an alias for `it`
- [`test(name, fn)`](https://facebook.github.io/jest/docs/api.html#basic-testing) is an alias for `it`
- `xdescribe(name, fn)`
- `xit(name, fn)`

Expand Down Expand Up @@ -352,7 +360,7 @@ describe('my beverage', () => {
it('is not sour', () => {
expect(myBeverage.sour).toBeFalsy();
});
})
});
```

To test an asynchronous function, just return a promise from `it`. When running tests, Jest will wait for the promise to resolve before letting the test complete.
Expand All @@ -371,6 +379,45 @@ describe('my beverage list', () => {

Even though the call to `it` will return right away, the test doesn't complete until the promise resolves as well.

You can use `.only` if you want to run only one test or describe block:

```js
describe.only('my beverage', () => {
it('is delicious', () => {
expect(myBeverage.delicious).toBeTruthy();
});

it('is not sour', () => {
expect(myBeverage.sour).toBeFalsy();
});
});

describe('my other beverage', () => {
// ... will be skipped
});
```

or

```js
it.only('will run', () => { /* ... */ });
it('will be skipped', () => { /* ... */ });
```

Or you can use `.skip` if you want to skip a test or a describe block:
```js
it.skip('will be skipped', () => { /* ... */ });
it('will run', () => { /* ... */ });
```

Alternatively you can use `test` instead of `it`. `test` is just an alias for `it` and
works exactly the same.
```js
test('something works', () => { /* ... */ });
test.skip('this test is skipped', () => { /* ... */ });
test.only('this test will run');
```

### `require.requireActual(moduleName)`

Returns the actual module instead of a mock, bypassing all checks on whether the
Expand Down
45 changes: 43 additions & 2 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ In your test files, Jest puts each of these methods and objects into the global
- [`describe(name, fn)`](#basic-testing)
- [`expect(value)`](#expect-value)
- [`it(name, fn)`](#basic-testing)
- [`it.only(name, fn)`](#basic-testing)
- [`it.skip(name, fn)`](#basic-testing)
- `fit(name, fn)` executes only this test. Useful when investigating a failure
- [`jest`](#the-jest-object)
- [`require.requireActual(moduleName)`](#require-requireactual-modulename)
- [`require.requireMock(moduleName)`](#require-requiremock-modulename)
- `test(name, fn)` is an alias for `it`
- [`test(name, fn)`](#basic-testing) is an alias for `it`
- `xdescribe(name, fn)`
- `xit(name, fn)`

Expand Down Expand Up @@ -160,7 +162,7 @@ describe('my beverage', () => {
it('is not sour', () => {
expect(myBeverage.sour).toBeFalsy();
});
})
});
```

To test an asynchronous function, just return a promise from `it`. When running tests, Jest will wait for the promise to resolve before letting the test complete.
Expand All @@ -179,6 +181,45 @@ describe('my beverage list', () => {

Even though the call to `it` will return right away, the test doesn't complete until the promise resolves as well.

You can use `.only` if you want to run only one test or describe block:

```js
describe.only('my beverage', () => {
it('is delicious', () => {
expect(myBeverage.delicious).toBeTruthy();
});

it('is not sour', () => {
expect(myBeverage.sour).toBeFalsy();
});
});

describe('my other beverage', () => {
// ... will be skipped
});
```

or

```js
it.only('will run', () => { /* ... */ });
it('will be skipped', () => { /* ... */ });
```

Or you can use `.skip` if you want to skip a test or a describe block:
```js
it.skip('will be skipped', () => { /* ... */ });
it('will run', () => { /* ... */ });
```

Alternatively you can use `test` instead of `it`. `test` is just an alias for `it` and
works exactly the same.
```js
test('something works', () => { /* ... */ });
test.skip('this test is skipped', () => { /* ... */ });
test.only('this test will run');
```

### `require.requireActual(moduleName)`

Returns the actual module instead of a mock, bypassing all checks on whether the
Expand Down