Jasmine Tweak: Show Passing Tests by Default
Posted: December 20, 2011 Filed under: Uncategorized | Tags: Jasmine, Javascript, Tweak, ui Leave a comment »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 43, 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.