next bit of functionality you want to add. • Write the functional code until the test passes. • Refactor both new and old code to make it well structured. - Martin Fowler, “TestDrivenDevelopment”, https://martinfowler.com/bliki/TestDrivenDevelopment.html
tests first really helps you avoid a lot of bad designs. It makes you think about the code you need to write, BEFORE you write it. 2. Once you have tests, they help you avoid introducing subtle bugs when you have to change the code later. Existing tests help prevent regressions in your code, where adding or changing one thing accidentally breaks another thing.
framework for unit and integration tests already in place • You can add libraries to it. • You can eject and substitute parts of the testing framework. • You can “eject” and then port the testing framework to other projects, or replace it with different testing libraries.
Display a list of links • Show how many times each link has been “favorited” • Allow a visitor to “favorite” links • You can fork or clone the repo from https://github.com/vjwilson/linkshare • Includes Git tags that are numbered for each step in this tutorial
Use this as a base, if you want to try TDD on your own. import React from 'react'; import ReactDOM from 'react-dom'; import App from './App'; it('renders without crashing', () => { const div = document.createElement('div'); ReactDOM.render(<App />, div); }); Git tag: 1-start-with-create-react-app
Names like scryRenderedDOMComponentsWithClass() • Don’t bother to learn it. Airbnb has released a testing utility called Enzyme, which makes it easy to assert, manipulate, and traverse your React Components' output. If you're deciding on a unit testing utility to use together with Jest, or any other test runner, it's worth checking out: http://airbnb.io/enzyme/ -from Facebook’s own documentation
jQuery, with functions like find(), children(), parent() etc. • Three functions for rendering: - Shallow stubs child components, good for unit tests - Mount renders all a components descendants, good for integration testing - Static renders to the final HTML that React would render.
with snapshot testing? Although it is possible to write snapshot files manually, that is usually not approachable. Snapshots help figuring out whether the output of the modules covered by tests is changed, rather than giving guidance to design the code in the first place. What About Snapshot Testing?