Jasmine webOS

Users' Guide

Here are more detailed instructions on how to get Jasmine webOS into your Palm® webOS™ application.

Download and Install

  1. Download the Jasmine webOS zipfile (from here)
  2. Unzip it into the root of your application. You should now have a plugins/jasmine-webos directory
  3. Download Jasmine
  4. Extract jasmine.js into plugins/jasmine-webos/app/lib
  5. Add these two entries into your application's sources.json file, preferably after all of your application code. Order is important: jasmine.js must be before jasmine-webos.js
{ "source": "plugins/jasmine-webos/app/lib/jasmine.js"},
{ "source": "plugins/jasmine-webos/app/lib/jasmine-webos.js"}

Writing Specs

Now that you can run specs, you need to write some. Here's how.


  1. Make a spec directory in the root of your application
  2. Build a directory tree under spec that mirrors your application code. For example, spec/app/assistants, spec/app/models, etc.
  3. For each file in app you should have a corresponding file in spec/app. So if you have a file that handles foo in app/models/foo.js, your spec file should be spec/models/foo-spec.js
  4. When you create a spec file, make sure to include that file in sources.json after the Jasmine files. To extend the example from above:
{ "source": "plugins/jasmine-webos/app/lib/jasmine.js"},
{ "source": "plugins/jasmine-webos/app/lib/jasmine-webos.js"},
{ "source": "spec/models/foo-spec.js"}

Mojo-independent Code

For any code that does not make any Palm Mojo API calls, writing your specs is straightforward. Write your specs according to the Jasmine User's Guide. The Sample Application (coming soon) has examples.

Mojo Dependent Code

Any code that is dependent on Mojo has some limitations. You can test Scene Assistants, but with a few key limitations. Jasmine webOS includes a Fake Mojo Depot for testing interactions with storage and a Mock Ajax implementation for testing making calls to remote servers.

You can find examples of each in the Sample Application (coming soon).

Add Spec Files to sources.json

All of your spec files need to be added to sources.json after the Jasmine files (see the example above). If these entries are not in sources.json then Jasmine will not know about your specs and thus won't be able to run them.

Running Specs

  1. Ensure that a Palm Emulator is running (you can run your tests on a phone, but they will run more slowly)
  2. Package & install your application as normal; ensure that it is not running
  3. From your command line, you need to launch the application with the correct parameter so the tests run:
palm-launch -p '{"runTests": true}'

Your app will come up and you should see Jasmine output like this:

Passing Specs in webOS UI

A progress bar, Jasmine version information, and the expectation results. If all your specs pass, the bar will be green.

If any spec fails, the bar will be red and the failed specs will be listed, like this:

Passing Specs in webOS UI

You can tap on any failed spec to see a list of all it's failing expectations, numbered, like this:

Passing Specs in webOS UI

At any time you can tap the 'All Results' button to see the results of all specs, passing and failing.

Passing Specs in webOS UI

Excluding Specs from Production

The Jasmine webOS plugin, Jasmine, and your spec files should not be included in your application when submitted to Palm for distribution. While this code will not affect your application, it does increase the package size and the time it takes the app to load.

Remove these files from sources.json and exclude your spec directory when packaging. See Palm's SDK documentation for how to do this.

Coming Soon

More Info