You are on page 1of 4

Exercise

Simple Test
#1 “Write a single test that will check that the
the viewmodel will load x books when x books
are loaded into the gateway using a stub”

Challenge 1. Stub the Gateway with fake data in the


test (which you collect from the api)
2. Execute code in the Black Box/SUT by
using an async/await to .load the data
and an observable to map the data to a
local Viewmodel
3. Check that the Gateway was called with
the correct arguments using a Spy
4. Check that the Viewmodel has the right
data in it by checking the .length and
each item[n].values
#2 Write a new test that will allow users to add a
new book (but don’t worry about reloading
the books after it’s added).

Power-up Then connect up the view like we did in the


demo. Your result should look like the below.
#3
Lesson Start
https://codesandbox.io/s/bftdd-lesson-31-v601y

1. Visit the link above and remember to open a codesandbox.io


account to save progress
2. Work on the starter project and complete the challenge

Resources 3. The solution is provided below but not the power-up!

Backend Test API

GET https://api.logicroom.co/api/<your email>/books (list)

POST https://api.logicroom.co/api/<your email>/books (add)


"Content-Type": "application/json"
{
"name": "x_name",
"author": "x_author"
}

Backend Test API reset


https://api.logicroom.co/api/<your email>/reset

Solution Template
https://codesandbox.io/s/bftdd-lesson-32-9y2x8

You might also like