with the live coding examples, it's best to have the following already installed before you come to this talk. Node (version 6, use nvm if you need to keep multiple versions Node) npm (comes with Node), or yarn, if you prefer that create-react-app CLI npm install -g create-react-app Your favorite text editor git, if you want to pull the sample repo, and check out the starting code for each part of the talk
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
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.
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.
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
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.
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. — https://facebook.github.io/jest/docs/snapshot-testing.html Jest Snapshot Testing
Use this as a base, if you want to try TDD on your own. it('renders a header with the appropriate class', () => { const wrapper = shallow(<App />); const header = wrapper.find('header'); expect(header).toHaveClassName('app-header'); }); Git tag: 3-starting-structure-for-easier-testing
of Cucumber.js I want to have documentation on Cucumber So that I can concentrate on building awesome applications Scenario: Reading documentation Given I am on the Cucumber.js GitHub repository When I click on "CLI" Then I should see "Running specific features" documentation.feature
user of Linkshare I want to see a list of links So that I can decide what articles I want to read Scenario: Viewing list of links Given I am on the Linkshare homepage When I look for a list of links Then I should see one or more link elements Scenario: Visiting a given link Given I am on the Linkshare homepage When I look for a list of links And I click the link text in the first link item Then I should visit the site in the link item href … documentation.feature (excerpt)
links; Given('I am on the Linkshare homepage', function() { return this.driver.get('http://localhost:3000'); }); When('I look for a list of links', function () { return this.driver.findElements({css: '.link-list .link- item'}).then(function(elements) { links = elements; }); }); Then('I should see one or more link elements', function () { assert.equal(links.length, 4); }); browser_steps.js (excerpt)
to End testing of React apps with Nightwatch”, https://blog.syncano.io/testing-syncano/ “Intern”, https://github.com/theintern/intern (a new framework for managing unit and functional tests, thanks to Jaydeep Parmar, @jaydeep98a, for this reference)