Multiple Jasmine Versions in one Project
The LaxarJS core in Version 1.0 already ships with built-in widget testing support for Jasmine v1.3, which can be imported using the AMD reference laxar/laxar_testing
.
However, in that testing framework, only widgets implemented in AngularJS are supported.
Also, the old builtin testing module contains several peculiarities which are sometimes confusing:
For example, events are delivered as a side-effect of "ticking" the virtual clock.
Because of the semantic versioning model used by LaxarJS, the old testing module will stay part of the core at least until LaxarJS v2.0 is released.
For the future (starting with LaxarJS v1.1.0), the laxar-mocks
library moves testing functionality out of the core.
Besides relying on the modern Jasmine v2.3, this test runner allows you to test non-angular widgets, provided that you have a corresponding adapter.
Of course, LaxarJS aims to support widgets using the old laxar/laxar_testing
and those using the new laxar-mocks
within the same application.
This means that both types of widgets will share a set of Bower components.
To avoid jasmine version conflicts, the HTML spec-runner expects a jasmine2
path to be configured with RequireJS in order to use laxar-mocks and Jasmine v2.3.
This allows you to install Jasmine versions 1.x and 2.x in the same project.
For more information on configuring Bower and RequireJS for laxar-mocks, check out the Installation instructions in the README.
Using the spec-runner configuration you can declare the jasmine version as well as the actual test-runner module to be used. The spec-runner configuration is respected by the HTML spec-runner as well as on the command line (when you call grunt test), through karma-laxar. This way you can choose among the testing frameworks.
Configuring the Spec-Runner
A widget's spec-runner configuration (spec_runner.js
) defines a property laxarSpec
on the global object (or on its module when running in node), with the following properties:
- the `title` of the spec test - the `tests` to be run (AMD module files in the same folder) - the AMD module of the `testRunner` to use. For the future and to use jasmine 2, use `'laxar-mocks'`. If nothing is specified, the old `'laxar/laxar_testing'` will be used. - the `jasmineMajorVersion` to use. When using `laxar-mocks` as the _testRunner_, make sure to specify `2`. By default, the major version `1` is assumed, which will work with the old testing module.
Usually, everything you need has been setup correctly by the widget template when creating your widget.
The only time that you have to edit the spec-runner configuration is when upgrading a widget from the old builtin testing module (and Jasmine 1.3.x) to using laxar-mocks
(and Jasmine 2.3.x).