Jasmine Tweak: Show Passing Tests by Default

One of the most useful tools for coding is a testing framework, to show when code breaks, and to also add to documentation. For my purposes, I recently learned about a small BDD framework known as Jasmine. I won’t describe how to use it, for that has been done well already. Instead, I’ll point out a small modification that I employed:

Problem:  I have to press ‘show passed’ to show passed tests every time I refresh the page.  I refresh every time I add a new test.  I want to have it show passed tests by default.

Solution:  Open the jasmine-html.js file.

On line 34, find

this.outerDiv = this.createDom('div', { className: 'jasmine_reporter' },

And replace with

this.outerDiv = this.createDom('div', { className: 'jasmine_reporter show-passed' },

Specifically, this adds the show-passed class to the reporter when it starts.

Then, we have to make the checkbox accurately reflect its on by default.

Find (line 41)

showPassed = this.createDom('input', { id: "__jasmine_TrivialReporter_showPassed__", type: 'checkbox' }),

and replace with

showPassed = this.createDom('input', { id: "__jasmine_TrivialReporter_showPassed__", type: 'checkbox', checked: true }),.

Now passed tests will show by default when you load the page.


3 Comments on “Jasmine Tweak: Show Passing Tests by Default”

  1. Paul S says:

    thanks, for this usefull instruction. But i think you transposed digits its line 34 and not 43 at least that’s how it was in my case. (Jasmine revision: 1315677058)

  2. cletusw says:

    In Jasmine 1.2.0 the line is 460. I think that’s the case for 1.1.0 as well.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s