Catching a zombie redirect event using mocha and chai expect

I was trying to write functional tests using zombie.js but for the life of me, couldn’t catch the redirect event that was firing. I have finally figured out what I was doing wrong. I was browsing to the page and then trying to catch the redirect, but of course, you have to listen for the redirect before you browse to the page (duh). I spent much longer than I want to admit…

Here is a simple demo of catching the event and testing a 301 redirect of google.com to www.google.com (using mocha and chai):