Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 16. Mocking and Stubbing > Using a Stub Library

16.5. Using a Stub Library

In Chapter 11, The Observer Pattern, we used a called flag and inline functions to verify that the observable interface notified observers when its notify method was called. Even though we didn’t use specific terminology to describe the pattern in that chapter, we now recognize these functions as test spies.

Because JavaScript’s functions are such powerful beasts, we can go a long way without a dedicated stubbing library. However, as we realized in Chapter 12, Abstracting Browser Differences: Ajax, declaring the flag and function quickly becomes repetitious, especially when using stubs and spies extensively. Even with the simple stubFn helper, we recognized that stubbing global interfaces, such as the ajax.create method, came with the burden of adding setUp and tearDown methods to ensure that the original interfaces were restored after the tests completed.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial