[Sugar-devel] Unit tests in Sugar HTML

Manuel Quiñones manuq at laptop.org
Mon May 13 10:24:23 EDT 2013


2013/5/13 Manuel Quiñones <manuq at laptop.org>:
> Hello,
>
> As I am currently implementing sugar palettes in HTML, I want to get
> the logic right, so I need unit tests.  Then I started to investigate
> unit testing in javascript.
>
> After looking for a bit, I decided to give a try to Jasmine framework,
> which is AngularJS choice.
>
> http://pivotal.github.io/jasmine/
>
> My first attempt was running the tests in the command line with jasmine-node.
>
> https://github.com/mhevery/jasmine-node
>
> But soon I realized that testing without access to the DOM is very
> limited.  For example, a palette needs to add a <div> to the document.
>  And my second test failed in jasmine-node because of that.
>
> So I went for Karma (previously named Testacular).
>
> http://karma-runner.github.io/
>
> It was easy to configure using RequireJS like is documented in:
>
> http://karma-runner.github.io/0.8/plus/RequireJS.html
>
> And it works!  You can try installing Karma (npm install -g karma) and
> then checking out in my clockjs activity.
>
> git checkout git://github.com/manuq/clockjs.git
> cd clockjs/lib/sugar-html-graphics
> karma start
>
> And then point a browser to the URL in the output, which points to Karma server.
>
> --
> .. manuq ..

Forgot to point you to my current testing spec, so you can see how
Jasmine tests look:

https://github.com/manuq/clockjs/blob/master/lib/sugar-html-graphics/test/paletteSpec.js

--
.. manuq ..


More information about the Sugar-devel mailing list