View a List of Todos

Story: As a user, I want to see all of todos in my todos list

To complete this story, we will need to create the TodoItem and MainSection components. Since this story does not involve making any changes to state, we will not have to write any more actions or reducers at this time.

TodoItem component

Should render correctly

It should be an li

Write the test.

// tests/todomvc/components/TodoItem.spec.js

'use strict';

import React from 'react'
import {expect} from 'chai'
import {shallow} from 'enzyme'

import TodoItem from '../../../src/todomvc/components/TodoItem'

function setup() {
  const component = shallow(
    <TodoItem/>
  );

  return {
    component: component
  }
}

describe('TodoItem component', () => {
  describe('Should render correctly', () => {
    it('Should be an li', () => {
      const {component} = setup();

      expect(component.type()).to.equal('li')
    })
  })
});

Run the test and watch it fail.

Write the code to make the test pass.

Run the test and watch it pass.

Commit changes.

It should have a label

Write the test.

Run the test and watch it fail.

Write the code to make the test pass.

Run the test and watch it pass.

Commit changes.

MainSection component

Should render correctly

It should be a MainSection component

Write the test.

Run the test and watch it fail.

Write the code to make the test pass.

Run the test and watch it pass.

Commit changes.

It should include a list of todos

Write the test.

Run the test and watch it fail.

Write the code to make the test pass.

Run the test and watch it pass.

Commit changes.

TodoApp Component

It should render correctly

It should have a MainSection

Write the test.

Run the test and watch it fail.

Write the code to make the test pass.

Run the test and watch it pass.

Commit changes.

Run It!

Now let's see what this looks like.

Open http://localhost:4000 in your web browser.

Type "Hello" into the text input box and see what happens. Then enter "World" You can see the todos appear in your list, as well as watch state update with each action in the Redux Dev Tools window on the right, like this:

Last updated

Was this helpful?