September 2017
Intermediate to advanced
120 pages
2h 47m
English
Testing user interfaces adds noise and complexity, so it’s best to test as much as you can without involving the user interface. Putting application logic in functions outside components lets us work more efficiently. In our word counter, we’ve already extracted the countWords function and placed it in a separate module:
| | function countWords(text) { |
| | return text ? text.match(/\w+/g).length : 0; |
| | } |
| | |
| | export default countWords; |
This module exports the countWords function by default. It’s a good idea to test this logic on its own, as long as you’re testing meaningful functionality instead of implementation details.
Create a new __tests__ directory in the src directory. The directory ...
Read now
Unlock full access