-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add src/setupTests.js to specify environment setup for Jest (#545)
- Loading branch information
Gael du Plessix
committed
Sep 2, 2016
1 parent
88ed883
commit 7312fe9
Showing
3 changed files
with
31 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ You can find the most recent version of this guide [here](https://github.com/fac | |
- [Writing Tests](#writing-tests) | ||
- [Testing Components](#testing-components) | ||
- [Using Third Party Assertion Libraries](#using-third-party-assertion-libraries) | ||
- [Initializing Test Environment](#initializing-test-environment) | ||
- [Focusing and Excluding Tests](#focusing-and-excluding-tests) | ||
- [Coverage Reporting](#coverage-reporting) | ||
- [Continuous Integration](#continuous-integration) | ||
|
@@ -674,6 +675,24 @@ import { expect } from 'chai'; | |
and then use them in your tests like you normally do. | ||
### Initializing Test Environment | ||
>Note: this feature is available with `[email protected]` and higher. | ||
If your app uses a browser API that you need to mock in your tests or if you just need a global setup before running your tests, add a `src/setupTests.js` to your project. It will be automatically executed before running your tests. | ||
For example: | ||
#### `src/setupTests.js` | ||
```js | ||
const localStorageMock = { | ||
getItem: jest.fn(), | ||
setItem: jest.fn(), | ||
clear: jest.fn() | ||
}; | ||
global.localStorage = localStorageMock | ||
``` | ||
### Focusing and Excluding Tests | ||
You can replace `it()` with `xit()` to temporarily exclude a test from being executed. | ||
|