Skip to content

Instantly share code, notes, and snippets.

@textbook
Created June 29, 2019 09:25
Show Gist options
  • Save textbook/4b01daa26ba89435ce03cab2091bbf93 to your computer and use it in GitHub Desktop.
Save textbook/4b01daa26ba89435ce03cab2091bbf93 to your computer and use it in GitHub Desktop.

CYF Conference 2019

Code Retreat

Overview

  • Each iteration will be 35 minutes of coding, followed by a 15 minute retro, followed by a 10 minute break.
  • We will be working in pairs and using test-driven development (TDD). Pairs switch after each iteration.
  • After each iteration, we will start from scratch - delete your code! The goal is the practice, not the code.

Setup

Everyone get into pairs! You'll need one laptop between two.

Create a new directory, enter it and create an NPM project. Accept the default settings, except for the test command; enter jest for that. Then install Jest. For example:

mkdir -p ~/cyf/conference/katas
cd ~/cyf/conference/katas
npm init  # test command: jest
npm install --save-dev jest

When you run the tests, using npm test, you should see:

No tests found
In <your directory>
  4 files checked.
  testMatch: **/__tests__/**/*.js?(x),**/?(*.)+(spec|test).js?(x) - 0 matches
  testPathIgnorePatterns: /node_modules/ - 4 matches
Pattern:  - 0 matches
npm ERR! Test failed.  See above for more details.

You are now ready to start!

Test-driven development

The rules of TDD are simple:

  1. Write a test (red)
  2. Make it pass ("green")
  3. Tidy up ("refactor")

You should only have one failing test at a time. Try and move in very small steps.

The first test, in rps.test.js:

const rps = require("./rps");

describe("rock, paper, scissors", () => {
  describe("as rock", () => {
    it("should beat scissors", () => {
      expect(rps("rock", "scissors")).toBe(true);
    });
  });
});
  • Call the shots. What will happen when you run this test?

  • Make a change. What's the smallest thing we could change to get a different error, even if we don't get it passing yet?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment