boot.js |
|
---|---|
Starting with version 2.0, this file "boots" Jasmine, performing all of the necessary initialization before executing the loaded environment and all of a project's specs. This file should be loaded after If a project is using Jasmine via the standalone distribution, this file can be customized directly. If a project is using Jasmine via the Ruby gem, this file can be copied into the support directory via The location of |
(function() {
|
Require & InstantiateRequire Jasmine's core files. Specifically, this requires and attaches all of Jasmine's code to the |
window.jasmine = jasmineRequire.core(jasmineRequire);
|
Since this is being run in a browser and the results should populate to an HTML page, require the HTML-specific Jasmine code, injecting the same reference. |
jasmineRequire.html(jasmine);
|
Create the Jasmine environment. This is used to run all specs in a project. |
var env = jasmine.getEnv();
|
The Global InterfaceBuild up the functions that will be exposed as the Jasmine public interface. A project can customize, rename or alias any of these functions as desired, provided the implementation remains unchanged. |
var jasmineInterface = {
describe: function(description, specDefinitions) {
return env.describe(description, specDefinitions);
},
xdescribe: function(description, specDefinitions) {
return env.xdescribe(description, specDefinitions);
},
it: function(desc, func) {
return env.it(desc, func);
},
xit: function(desc, func) {
return env.xit(desc, func);
},
beforeEach: function(beforeEachFunction) {
return env.beforeEach(beforeEachFunction);
},
afterEach: function(afterEachFunction) {
return env.afterEach(afterEachFunction);
},
expect: function(actual) {
return env.expect(actual);
},
pending: function() {
return env.pending();
},
spyOn: function(obj, methodName) {
return env.spyOn(obj, methodName);
},
addCustomEqualityTester: function(tester) {
env.addCustomEqualityTester(tester);
},
jsApiReporter: new jasmine.JsApiReporter({
timer: new jasmine.Timer()
})
};
|
Add all of the Jasmine global/public interface to the proper global, so a project can use the public interface directly. For example, calling |
if (typeof window == "undefined" && typeof exports == "object") {
extend(exports, jasmineInterface);
} else {
extend(window, jasmineInterface);
}
|
Expose the interface for adding custom equality testers. |
jasmine.addCustomEqualityTester = function(tester) {
env.addCustomEqualityTester(tester);
};
|
Expose the interface for adding custom expectation matchers |
jasmine.addMatchers = function(matchers) {
return env.addMatchers(matchers);
};
|
Expose the mock interface for the JavaScript timeout functions |
jasmine.clock = function() {
return env.clock;
};
|
Runner ParametersMore browser specific code - wrap the query string in an object and to allow for getting/setting parameters from the runner user interface. |
var queryString = new jasmine.QueryString({
getWindowLocation: function() { return window.location; }
});
var catchingExceptions = queryString.getParam("catch");
env.catchExceptions(typeof catchingExceptions === "undefined" ? true : catchingExceptions);
|
ReportersThe |
var htmlReporter = new jasmine.HtmlReporter({
env: env,
queryString: queryString,
onRaiseExceptionsClick: function() { queryString.setParam("catch", !env.catchingExceptions()); },
getContainer: function() { return document.body; },
createElement: function() { return document.createElement.apply(document, arguments); },
createTextNode: function() { return document.createTextNode.apply(document, arguments); },
timer: new jasmine.Timer()
});
|
The |
env.addReporter(jasmineInterface.jsApiReporter);
env.addReporter(htmlReporter);
|
Filter which specs will be run by matching the start of the full name against the |
var specFilter = new jasmine.HtmlSpecFilter({
filterString: function() { return queryString.getParam("spec"); }
});
env.specFilter = function(spec) {
return specFilter.matches(spec.getFullName());
};
|
ExecutionReplace the browser window's |
var currentWindowOnload = window.onload;
window.onload = function() {
if (currentWindowOnload) {
currentWindowOnload();
}
htmlReporter.initialize();
env.execute();
};
|
Helper function for readability above. |
function extend(destination, source) {
for (var property in source) destination[property] = source[property];
return destination;
}
}());
|