- 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.
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!
The rules of TDD are simple:
- Write a test (red)
- Make it pass ("green")
- 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?