|
1 | 1 | # Writing Tests
|
2 | 2 |
|
3 |
| -Because most of the Redux code you write are functions, and many of them are pure, they are easy test without mocking. |
| 3 | +Because most of the Redux code you write are functions, and many of them are pure, they are easy to test without mocking. |
4 | 4 |
|
5 | 5 | ### Setting Up
|
6 | 6 |
|
7 | 7 | We recommend [Mocha](http://mochajs.org/) as the testing engine.
|
8 |
| -Note that it runs in a Node environment, so you won’t have access to DOM. |
| 8 | +Note that it runs in a Node environment, so you won’t have access to the DOM. |
9 | 9 |
|
10 | 10 | ```
|
11 | 11 | npm install --save-dev mocha
|
@@ -349,7 +349,7 @@ describe('components', () => {
|
349 | 349 |
|
350 | 350 | #### Fixing Broken `setState()`
|
351 | 351 |
|
352 |
| -Shallow rendering currently [throws an error if `setState` is called](https://github.com/facebook/react/issues/4019). React seems to expect that, if you use `setState`, DOM is available. To work around the issue, we use jsdom so React doesn’t throw the exception when DOM isn’t available. Here’s how to [set it up](https://github.com/facebook/react/issues/5046#issuecomment-146222515): |
| 352 | +Shallow rendering currently [throws an error if `setState` is called](https://github.com/facebook/react/issues/4019). React seems to expect that, if you use `setState`, the DOM is available. To work around the issue, we use jsdom so React doesn’t throw the exception when the DOM isn’t available. Here’s how to [set it up](https://github.com/facebook/react/issues/5046#issuecomment-146222515): |
353 | 353 |
|
354 | 354 | ```
|
355 | 355 | npm install --save-dev jsdom
|
@@ -398,7 +398,7 @@ In a unit test, you would normally import the `App` component like this:
|
398 | 398 | import App from './App';
|
399 | 399 | ```
|
400 | 400 |
|
401 |
| -However when you import it, you’re actually holding the wrapper component returned by `connect()`, and not the `App` component itself. If you want to test its interaction with Redux, this is good news: you can wrap it in a [`<Provider>`](https://github.com/rackt/react-redux#provider-store) with a store created specifically for this unit test. But sometimes you want to test just the rendering of the component, without a Redux store. |
| 401 | +However, when you import it, you’re actually holding the wrapper component returned by `connect()`, and not the `App` component itself. If you want to test its interaction with Redux, this is good news: you can wrap it in a [`<Provider>`](https://github.com/rackt/react-redux#provider-store) with a store created specifically for this unit test. But sometimes you want to test just the rendering of the component, without a Redux store. |
402 | 402 |
|
403 | 403 | In order to be able to test the App component itself without having to deal with the decorator, we recommend you to also export the undecorated component:
|
404 | 404 |
|
|
0 commit comments