See the Number of Todos To Be Completed

Story: As a user, I want to see how many remaining todos I have to complete.

Should render correctly

Write the test.

// tests/todomvc/components/Footer.spec.js

'use strict';

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

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

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

  return {
    component: component
  }
}

describe('Footer component', () => {
  describe('Should render correctly', () => {
    it('Should be a Footer', () => {
      const {component} = setup();

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

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 todo counter

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.

Should behave correctly

It should display 'No todos left' when active count is 0

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 display '1 todo left' when active count is 1

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 display '5 todos left' when active count is 5

Five is used randomly here. It can be any other integer greater than one.

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

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.

You should immediately see the 'The number of todos not completed: No todos left' message.

Add a todo and see the message change to 'The number of todos not completed: 1 todo left'.

Add some more todos and set their completed status. See the message change accordingly.

Last updated

Was this helpful?