Project: The Testable Death Square
The rebels are on board our death square, and are heading for our datbanks! A platoon of storm troopers has been sent to stop them, but we need to know the second they go offline so we can switch to a backup. Let's do some TDD!
Instructions:
-
Open up our data banks. Go into
turret-api
, runseed.js
andserver.js
...but don't forget to install those npm modules! -
Go into
imperial-starfleet
and start up our front end. -
Run
ng test
insideimperial-starfleet
. Nice, passing two tests. But one failing test on InfoWindow! Let's make it pass. -
That failing test is complaining about
No provider for Http
. WhatModule
could we import toinfo-window.component.spec.ts
? Hint: it's towards the top ofapp.module.ts
. Don't forget to add it to animports
array below thedeclarations
array inTestBed.configureTestingModule
. Save the file, and check theng test
browser output. -
Woo hoo, we're failing again! We need to import one more thing. It's called
RouterTestingModule
and it comes from the@angular/router/testing
package. Don't forget to add it to theimports
array, too. Save the file, and check theng test
browser output one more time. -
Create a new test below the 'should be created' one, and call it 'should have a findTurret function to get data from the data banks'. Fail this test the old fashioned way, by making it test
expect(true).toEqual(false);
. -
Let's actually test something now. We're going to make a lot of changes to our Death Square Dashboard™, and we need to make sure that
findTurret
is still a working function. Replace ourexpect(true)...
expectation withexpect(typeof(component.findTurret)).toBe('function');
-
Check your tests in Chrome one more time. Once they are all passing, we know one more thing is safe from those blasted rebels!