Jasmine¶
Jasmine test runner extension.
Ensure
TESTING
configuration variable is set toTrue
.Reinstall assets (with
TESTING = True
).(invenio)$ cdvirtualenv src/invenio-demosite (invenio)$ inveniomanage bower -i bower-base.json > bower.json (invenio)$ bower install (invenio)$ inveniomanage collect (invenio)$ inveniomanage assets build
Run tests by loading http://localhost:4000/jasmine/specrunner in your browser.
Missing features¶
- Console test runner (likely we will use Karma test runner).
- CI integration.
FlightJS tests¶
Following is an example of a very simple FlightJS component which is normally
added in your Invenio module under static/js/**/*.js
:
// invenio/modules/*/static/js/mycomponent.js
define(function(require) {
'use strict';
var defineComponent = require('flight/lib/component');
return defineComponent(mycomponent);
function mycomponent() {
this.attributes({
myattr: 'somevalue',
});
// ...
this.after('initialize', function() {
// ...
});
}
});
To test above FlightJS component, create a spec file in
testsuite/js/**/*.spec.js
:
// invenio/modules/*/testsuite/js/mycomponent.spec.js
'use strict';
describeComponent('js/mycomponent', function() {
// Initialize the component and attach it to the DOM
beforeEach(function() {
this.setupComponent();
});
it('should be defined', function() {
expect(this.component).toBeDefined();
});
});
Fixtures¶
To load fixtures (created under testsuite/js/**/*.html
) for the test.
Inside the spec file take following steps:
jasmine.getFixtures().fixturesPath =
'/jasmine/spec/invenio.modules.<module_name>/';
readFixtures('<fixture_name>')
See https://github.com/flightjs/jasmine-flight for further examples how to test FlightJS components.
HOWTO¶
Mock AJAX request¶
See http://jasmine.github.io/2.0/ajax.html for further information.