Giter Club home page Giter Club logo

react-tdd's Introduction

React TDD

Objectives

  • Practice TDD workflow to create a simple CRUD app with React
  • Use Enzyme's shallow function to test React components without their child components
  • Write assertions using Jest
  • Use sinon to create stubs/spies

Rationale

TDD is a requirement in modern software development. The functional nature of React, combined with helpful libraries like enzyme make the React TDD workflow very appealing. However, without practice developers might be tempted to fall back to pre-TDD ways. This exercise gives students practice with the TDD workflow and enzyme.

Setup

  1. Fork this repo.
  2. Clone your fork.
  3. Run yarn install.
  4. Run yarn test and verify existing tests pass.
  5. Run yarn start to view app in the browser.

Instructions

This repo contains an empty react app. Your job is to implement the following user stories in TDD fashion:

  1. Given a browser, when I browse to the site, then I see an "Add Person" button.
  2. Given I see the "Add Person" button, when I click it, then I am taken to an Add Person page.
  3. Given I am on the Add Person page, when I fill in the fields and click "Add", I am taken back to the list page.
  4. Given that I have added a person, when I am on the list page, then I see my people.
  5. Given that I see people in the list, when I click a person, I am taken to a Person Edit page.
  6. Given I am on the person edit page, when I change a persons name and click Save, then I am taken back to the list page.
  7. Given that I have made updates to people, when I am on the list page, I should see the modified information.
  8. Given that I am on the edit page, then I see a delete button.
  9. Given that I am on the edit page, when I click the delete button, then I am taken back to the list page.
  10. Given that I have deleted a person, when I am on the list page, then I no longer see the deleted people.

Tips:

  • Use simulate to simulate text change and click events
  • Use sinon to stub the onEdit() call
  • Verify the stub was called with the correct arguments.
  • Use controlled components for input.

Resources

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.