chai-jq - jQuery Assertions for Chai

Wednesday, November 27, 2013

A New jQuery Plugin for Chai

Chai is a wonderful JavaScript test assertion library that I rely on extensively (usually using it in conjunction with the Mocha test framework library). Chai has an intuitive, natural-language approach to assertions that enables you tests to read almost like an English narrative. Chai also supports plugins which extend the base assertion API.

Chai is quite often used for frontend JavaScript testing, and specifically for testing jQuery elements in an application web page. There is an existing chai-jquery plugin for Chai, which is extensive and really quite neat. Unfortunately, it has a few issues with overriding built-in Chai assertions like have and length in ways that changes the underlying Chai API.

With that motivation in mind, I hacked together a quick jQuery plugin, chai-jq for Chai that has a separate $-prefixed namespace to avoid collisions with existing Chai assertions, and put the project up on GitHub.

The chai-jq Plugin

The chai-jq plugin has full documentation at the project website, including installation instructions. The plugin works in all of the following environments:

  • Browser: Via a standard <script> tag include.
  • Browser + AMD: Via an AMD library like RequireJS.
  • Node.js + JsDom: In Node.js using the JsDom browser environment emulator.

In terms of what chai-jq provides, here is a brief tour of the API (stolen from the project docs):

Read more...

Writing a Technical Book, Part 2 - Authoring

Monday, November 25, 2013

Writing a Book

This is the second in a series of posts on my experiences writing my first technical book, Backbone.js Testing, published in July, 2013. In this article, I reflect on the task of authoring the core of the book - from writing the first pages to finishing off the last round of technical edits and submission of the full draft of the book to my publisher.

A rough overview of salient tips and experiences from this part of the book-writing journey includes:

  • Make sure to have a reliable backup of your work - expect to lose all your files (and your computer).
  • Before writing anything, plan and outline everything.
  • The writing process will take much longer than you think it will.
  • The writing process is also tiring, stressful, and boring.
  • Technical review will bruise your ego and leave you with a much better book.
  • Once you get most of the way through the drafting process, you (the author) hold the power in your relationship with your publisher.

Where we Left Off

In my previous post on starting a book project, I discussed how I got roped into writing a technical book and the process from initial contact from the publisher to signing a book contract. As part of the negotiations, we agreed on the following ultimate chapter outline (with estimated page count and due dates):

  1. Setting up a Test Infrastructure (10 pages) - Jan. 8, 2013
  2. Creating a Backbone.js Application Test Plan (8 pages) - Jan. 16, 2013
  3. Test Assertions, Specs, and Suites (20 pages) - Jan. 28, 2013
  4. Test Spies (7 pages) - Feb. 4, 2013
  5. Test Stubs and Mocks (15 pages) - Feb. 11, 2013
  6. Headless Web Testing (12 pages) - Feb. 19, 2013
  7. Appendix A: Other JavaScript Test Frameworks (8 pages) - Feb. 25, 2013

As a spoiler for the rest of this post - I came nowhere near making most of the chapter deadlines.

Starting on the Book

After signing the contract in mid-December, I found that I suddenly had my first chapter due Jan. 8 and subsequent chapters following quickly after that. Shortly thereafter, I dug in and started getting my authoring and coding tools set up, enhancing my book outline, and dove into writing the first chapter.

Read more...

Learn Frontend Testing

Friday, October 18, 2013

Learn Frontend Testing

As a part of Formidable Labs’ series of development education events, I led a ”Learn Frontend Testing” workshop on Oct. 16, 2013 for the SeattleJS meetup group. My slides are available at the following locations:

  • Web Presentation: A live, navigable reveal.js website. (Note: use the space bar to advance slides and arrow keys to navigate.)
  • PDF: A download-able PDF.

And, here’s an embedded format:

Read more...

Packt Holiday eBook Sale

Wednesday, October 16, 2013

Packt Holiday Discount

Packt Publishing is offering a pretty respectable 50% off all of their eBooks through Oct. 17th. They’ve got a Columbus Day special code of COL50 to enter during checkout. (For those not quite comfortable with Columbus Day, consider it a Bartolomé Day discount.)

Read more...

Backbone.js Testing - Book Contest

Monday, September 09, 2013

Win Free Copies of Backbone.js Testing

I’m pleased to announce that Packt Publishing is organizing a contest to give away copies of my book, Backbone.js Testing!

Five participants stand a chance to win digital copies of the book.

Book Overview

Backbone.js Testing covers Backbone.js test architecture and development, and in brief summary will help you:

  • Create comprehensive test infrastructures.
  • Understand and utilize modern frontend testing techniques and libraries.
  • Use mocks, spies, and fakes to effortlessly test and observe complex Backbone.js application behavior.
  • Automate tests to run from the command line, shell, or practically anywhere.

Enter the Contest, Win the Book!

All you need to do is leave a comment below with what interests you most about the book. You can get a good sense of the book’s content by looking at it’s product description on Packt’s book page.

Deadline: The contest will close in one week’s time. Winners will be contacted by Packt via email, so be sure to use your real email address when you comment! (Alternately, after leaving a comment you can instead email me at ryan@loose-bits.com if you don’t want your email address to publicly appear on this page.)

Read more...