Verifying Test Doubles

Learn how to verify test doubles with testdouble.js, the side effect, and to write the tests for test doubles verification.

Verifying doubles with testdouble.js

Using test doubles is more than just setting stubbed behaviors to replace real behaviors. Test doubles are also used to verify behavior by showing that various methods were called as side effects of the code under test. In RSpec, this verification is done with expect and have_received. In testdouble.js, it’s done with the td.verify method.

Side effects

There is a side effect in this code. When we move a task up or down, the JavaScript still makes an Ajax call back to the server to register the change server-side. We don’t really care about the result of that call (at least not for the purposes of this test), but we do care that it gets made. So, we can put that validation into the tests by changing the “move up” and “move down” tests.

Writing the tests

First we put some imports at the top of the file:

Get hands-on with 1200+ tech skills courses.