Sugar-coated testing framework built around RequireJS, Mocha, Chai and Blanket.js
- Easy configuration of Blanket.js with Mocha and AMD (based on the mochablanket adapter provided by Blanket.js)
- Toggle Blanket.js coverage report with automatic browser reload
- Persisted test settings ("mocha report", "coverage report" and "show fixtures") across reloads (using HTML5 local storage)
- Base test utility functions for writing clean Mocha tests with less code
Compared to the standard Mocha HTML output, Sugarspoon adds a settings bar at the bottom:
Files names in the coverage report can be clicked to show line-based coverage (this is standard Blanket.js):
- Installing Sugarspoon using bower
- See the example directory for a working demonstration
- Defining your tests using RequireJS
- Some general notes on Mocha and testing approaches
- Base test utility functions for namespacing an cleanup in your Mocha tests
- How to get selective coverage reporting with Blanket.js
- Best practices for writing your tests
- Some more testing techniques
- The
@utils.view.create()
function exposed byviewTest()
now supports a "root" option (takes a jQuery selector string) to allow binding to a nested view element (when combined with the "html" option), while still getting the entire HTML structure to be cleaned up automatically in theafter()
.
- ... and actually compiled v0.3.5 to JavaScript. It must be Friday.
- Fix typo that broke
@util.view.create()
- Fixed error in
ViewTestManager.setClass()
if no "render" method is defined on your class. - Fixed error (usually thrown from
afterEach()
) if view class has no "remove" method. - Expanded the functionality of
@util.view.create()
: if no "el" is specified, it is automatically created as first child in the Fixtures container div. If it is specified, but false (e.g.{el: null}
), it will rely the Backbone View to create the view element itself, after which it will append the view.$el to the Fixtures container div.
TestManager
now has anautoResetSpies
property (defaults to true). If set to false, you can reset the Sinon spies (created through the@sandbox
) yourself using@testManager.resetSandboxSpies()
.
- Add support for grunt-blanket-mocha for getting test coverage output on the command-line.
- The
blanketOptions
passed to theTestRunner
can now be a function, to allow for the grunt-blanket-mocha reporter option to be set only if running in PhantomJS (see the example directory). - Refactored the Gruntfile and TestRunner.
- Moved many bower dependencies from dev-only dependencies to the normal "dependencies" list, since you will actually need them to use Sugarspoon.
- Extensively updated documentation
- Avoided loading the regular Mocha testrunner when using the Blanket coverage runner
- Added
baseTest()
,viewTest()
,modelTest()
andcollectionTest()
utility functions, along with unit tests for their functionality. - Added a special
meta/sanitycheck
test suite to for checking left-behind properties on the Mocha test context.
- Fix leftbehind
loadNpmTasks
calls in Gruntfile - Renamed
adapters
andrunners
directories toadapter
andrunner
- Fix semver tag for bower
- Mocha is no longer loaded using RequireJS – it should be loaded through a regular script tag instead. This is for compatibility with grunt-mocha
- The API of the
TestRunner.run()
has changed; instead of passing the actual modules to run, you should now pass a list of module names to be loaded (using RequireJS). The TestRunner now makes sure to execute the test suites in order. Note that you still have to make sure to return a function from the test module instead of the direct call todescribe()
. - Removed default Blanket
filter
in theCoverageRunner
. Configuration options for Blanket can now be passed to theTestRunner
as ablanketOptions
object. Thecoverage
option on theTestRunner
has been removed. - Added .editorconfig and coffeelint for syntax checking.
- Changed Sugarspoon source code from 4 spaces to 2 spaces.
- More flexible jQuery dependency in
bower.json
; any 2.x version should be fine.
- First public release; mostly to be considered as proof-of-concept
Sugarspoon started as part of the Goeie Jongens HTML5 toolkit and was further developed for Easytobook.com.
I wanted to unit test my JavaScript code and optionally have coverage reporting. Although Blanket.js has some separate examples of usage with AMD/RequireJS and Mocha, I found it non-trivial to get the combination to work.
Also, since adding Blanket.js introduces quite a bit of overhead (feels about 2x slower with coverage reporting enabled), I wanted a way to quickly enable or disable coverage in the Mocha web UI.
While I was at it, I also added some extra configuration options to show/hide the detailed Mocha output itself, as well as some very simple HTML fixtures management (Backbone view elements).
Finally, recognizing that the shared testing context in Mocha tests can lead to undesired side-effects between tests, several base test utility functions were added to help namespace data and behavior on the test context and clean them up automatically.