[archive] JS Live Class Day 1: Activities


Download, install, and setup Node.js.

Launch the REPL and ensure you can run some commands

Finally, download the code and get it running.

Test-Driven Development

Writing really solid unit tests is a non-negotiable skill for an engineer to master. Unfortunately, they are also shrouded in mystery. Take a look at the following resources to understand the rationale behind my testing setup:

Learn about Constructors and Prototypes

Create a constructor function and a prototype for an Animal .

Here’s a test to try to make pass:

const animal = new Animal();

test.ok( animal instanceof Animal, 'should create an instance of Animal' );

Create a function on Animal ‘s prototype called speak  that returns the animal’s sound.

const animal = new Animal();
const expected = 'generic sound';
const actual = animal.speak();

test.equal( actual, expected, 'should make a generic sound when it speaks' );


Create two new constructors with prototypes that inherit from Animal: Reptile and Primate.  Overwrite the speak  method for each.

let actual, expected;

const reptile = new Reptile();

test.ok( reptile instanceof Reptile, 'should be an instance of Reptile' );
test.ok( reptile instanceof Animal, 'should be an instance of Animal' );

expected = Reptile.SOUND;
actual = reptile.speak();
test.equal( actual, expected, 'should make a reptile sound when it speaks' );

const primate = new Primate();

test.ok( primate instanceof Primate, 'should be an instance of Primate' );
test.ok( primate instanceof Animal, 'should be an instance of Animal' );

expected = Primate.SOUND;
actual = primate.speak();
test.equal( actual, expected, 'should make a primate sound when it speaks' );