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. ...
Get Test-Driving JavaScript Applications now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.