Prepares and executes jasmine in the current environment, only if jasmine is not defined. This is useful for having self-executing test files.
When your IDE is configured to execute .js
files through node
(like with a Sublime build system), this allows you quickly run a test without having to configure anything.
- Add this module and
jasmine
as dependencies:
$ npm install --save-dev jasmine run-jasmine
- Then, in your test files, add:
require('run-jasmine')();
Say you have test/verify-test.js
, and it looks like this:
require('run-jasmine')();
describe('verify-test', () => {
it('works', () => {
expect(true).toBe(true);
});
});
By calling run-jasmine
before the specs are defined, you can run this test in two ways:
- Through jasmine, with
./node_modules/.bin/jasmine test/verify-test.js
. - Or, by running the script directly, with
node test/verify-test.js
.