Review and Run
The journey started with a desire to write automated tests for the function with dependencies. In the end, in addition to the fast tests passing, the net result is a pretty good design compared to what we saw in the spike. Let’s take a few minutes to review the tests we wrote.
-
test/create-url-test.js: Here, we started with the tests for the createURL function. We avoided dealing with any dependencies while writing these tests.
-
test/setlocation-test.js: In this file we wrote a test for the setLocation function. Since setLocation interacts with the window object, we mocked it using a lightweight JSON object with a location property.
-
test/sinon-setup.js: We created this file to host the setup and teardown functions for Sinon sandbox. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access