Main Content

Organizing Your Code with Testable jQuery Plugins

A talk by andyp

About the Talk

April 25, 2010 10:45 AM

At Carbon Five we've used jQuery on a wide range of consulting projects over the past three years—from simple progressive enhancement of the user interaction to rich Javascript applications, chat clients and charting. We have experimented with different ways to structure our code: none, MVC, etc. We finally evolved to a style that allows us to build complex pages, with numerous plugins, without creating a mess of Javascript.

These learnings have been driven by our desire to unit test our code, and at times, do test-driven Javascript development. Through those experiences we've learned good patterns for structuring and testing our code.

Showing real-world examples, we'll talk about:

  • Using the jQuery plugin model to structure our code. We have adopted this pattern not just for re-usable plugins, but also for page-specific code. We've evolved our thinking as to what the page should do, what the plugin should do, and what markup should be on the page. What are good patterns to divide responsibilities?
  • Using BDD to test drive JavaScript coding. When you have a general notion of where you are going, the best technique may be to write tests to home in on the requirements. We have been fairly successful using this technique, including in areas where you might not expect—like drag-n-drop
  • Getting the full benefit out of unit tests by making them executable in an automated fashion on a continuous basis. We've been successful using BlueRidge (and a similar Maven offering) to run our Javascript unit on continuous integration servers (Bamboo/Team City). These have proven much more reliable than our forays into doing the same thing with Selenium and in-browser driving of JSUnit. We'll discuss this technique and walk through setting it up.

Ratings and Recommendations

Avg. Rating

Average based
on 3 ratings

comments powered by Disqus