Deprecate getResults() (use results()). Add some unit test coverage for jasmine.Spec. Add some unit test coverage for JsApiReporterSpec.
This commit is contained in:
@@ -16,11 +16,7 @@ jasmine.Block.prototype.execute = function(onComplete) {
|
||||
try {
|
||||
this.func.apply(this.spec);
|
||||
} catch (e) {
|
||||
this.fail(e);
|
||||
this.spec.fail(e);
|
||||
}
|
||||
onComplete();
|
||||
};
|
||||
|
||||
jasmine.Block.prototype.fail = function(e) {
|
||||
this.spec.results.addResult(new jasmine.ExpectationResult(false, jasmine.util.formatException(e), null));
|
||||
};
|
||||
19
src/Env.js
19
src/Env.js
@@ -30,6 +30,9 @@ jasmine.Env.prototype.clearTimeout = jasmine.clearTimeout;
|
||||
jasmine.Env.prototype.setInterval = jasmine.setInterval;
|
||||
jasmine.Env.prototype.clearInterval = jasmine.clearInterval;
|
||||
|
||||
/**
|
||||
* @returns an object containing jasmine version build info, if set.
|
||||
*/
|
||||
jasmine.Env.prototype.version = function () {
|
||||
if (jasmine.version_) {
|
||||
return jasmine.version_;
|
||||
@@ -38,6 +41,20 @@ jasmine.Env.prototype.version = function () {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns a sequential integer starting at 0
|
||||
*/
|
||||
jasmine.Env.prototype.nextSpecId = function () {
|
||||
return this.nextSpecId_++;
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns a sequential integer starting at 0
|
||||
*/
|
||||
jasmine.Env.prototype.nextSuiteId = function () {
|
||||
return this.nextSuiteId_++;
|
||||
};
|
||||
|
||||
/**
|
||||
* Register a reporter to receive status updates from Jasmine.
|
||||
* @param {jasmine.Reporter} reporter An object which will receive status updates.
|
||||
@@ -98,7 +115,7 @@ jasmine.Env.prototype.it = function(description, func) {
|
||||
|
||||
jasmine.Env.prototype.xit = function(desc, func) {
|
||||
return {
|
||||
id: this.nextSpecId_++,
|
||||
id: this.nextSpecId(),
|
||||
runs: function() {
|
||||
}
|
||||
};
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
jasmine.JsApiReporter = function() {
|
||||
this.started = false;
|
||||
this.finished = false;
|
||||
this.suites = [];
|
||||
this.results = {};
|
||||
this.suites_ = [];
|
||||
this.results_ = {};
|
||||
};
|
||||
|
||||
jasmine.JsApiReporter.prototype.reportRunnerStarting = function(runner) {
|
||||
@@ -14,10 +14,14 @@ jasmine.JsApiReporter.prototype.reportRunnerStarting = function(runner) {
|
||||
var suites = runner.suites();
|
||||
for (var i = 0; i < suites.length; i++) {
|
||||
var suite = suites[i];
|
||||
this.suites.push(this.summarize_(suite));
|
||||
this.suites_.push(this.summarize_(suite));
|
||||
}
|
||||
};
|
||||
|
||||
jasmine.JsApiReporter.prototype.suites = function() {
|
||||
return this.suites_;
|
||||
};
|
||||
|
||||
jasmine.JsApiReporter.prototype.summarize_ = function(suiteOrSpec) {
|
||||
var isSuite = suiteOrSpec instanceof jasmine.Suite
|
||||
var summary = {
|
||||
@@ -35,6 +39,14 @@ jasmine.JsApiReporter.prototype.summarize_ = function(suiteOrSpec) {
|
||||
return summary;
|
||||
};
|
||||
|
||||
jasmine.JsApiReporter.prototype.results = function() {
|
||||
return this.results_;
|
||||
};
|
||||
|
||||
jasmine.JsApiReporter.prototype.resultsForSpec = function(specId) {
|
||||
return this.results_[specId];
|
||||
};
|
||||
|
||||
//noinspection JSUnusedLocalSymbols
|
||||
jasmine.JsApiReporter.prototype.reportRunnerResults = function(runner) {
|
||||
this.finished = true;
|
||||
@@ -46,9 +58,9 @@ jasmine.JsApiReporter.prototype.reportSuiteResults = function(suite) {
|
||||
|
||||
//noinspection JSUnusedLocalSymbols
|
||||
jasmine.JsApiReporter.prototype.reportSpecResults = function(spec) {
|
||||
this.results[spec.id] = {
|
||||
messages: spec.results.getItems(),
|
||||
result: spec.results.failedCount > 0 ? "failed" : "passed"
|
||||
this.results_[spec.id] = {
|
||||
messages: spec.results().getItems(),
|
||||
result: spec.results().failedCount > 0 ? "failed" : "passed"
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -2,19 +2,24 @@ jasmine.Matchers = function(env, actual, results) {
|
||||
this.env = env;
|
||||
this.actual = actual;
|
||||
this.passing_message = 'Passed.';
|
||||
this.results = results || new jasmine.NestedResults();
|
||||
this.results_ = results || new jasmine.NestedResults();
|
||||
};
|
||||
|
||||
jasmine.Matchers.pp = function(str) {
|
||||
return jasmine.util.htmlEscape(jasmine.pp(str));
|
||||
};
|
||||
|
||||
/** @deprecated */
|
||||
jasmine.Matchers.prototype.getResults = function() {
|
||||
return this.results;
|
||||
return this.results_;
|
||||
};
|
||||
|
||||
jasmine.Matchers.prototype.results = function() {
|
||||
return this.results_;
|
||||
};
|
||||
|
||||
jasmine.Matchers.prototype.report = function(result, failing_message, details) {
|
||||
this.results.addResult(new jasmine.ExpectationResult(result, result ? this.passing_message : failing_message, details));
|
||||
this.results_.addResult(new jasmine.ExpectationResult(result, result ? this.passing_message : failing_message, details));
|
||||
return result;
|
||||
};
|
||||
|
||||
|
||||
@@ -66,11 +66,11 @@ jasmine.Queue.prototype.finish = function () {
|
||||
}
|
||||
};
|
||||
|
||||
jasmine.Queue.prototype.getResults = function () {
|
||||
jasmine.Queue.prototype.results = function () {
|
||||
var results = new jasmine.NestedResults();
|
||||
for (var i = 0; i < this.blocks.length; i++) {
|
||||
if (this.blocks[i].getResults) {
|
||||
results.addResult(this.blocks[i].getResults());
|
||||
if (this.blocks[i].results) {
|
||||
results.addResult(this.blocks[i].results());
|
||||
}
|
||||
}
|
||||
return results;
|
||||
|
||||
@@ -46,6 +46,11 @@ jasmine.Runner.prototype.suites = function() {
|
||||
return this.suites_;
|
||||
};
|
||||
|
||||
jasmine.Runner.prototype.results = function() {
|
||||
return this.queue.results();
|
||||
};
|
||||
|
||||
/** @deprecated */
|
||||
jasmine.Runner.prototype.getResults = function() {
|
||||
return this.queue.getResults();
|
||||
return this.queue.results();
|
||||
};
|
||||
35
src/Spec.js
35
src/Spec.js
@@ -7,8 +7,14 @@
|
||||
* @param {String} description
|
||||
*/
|
||||
jasmine.Spec = function(env, suite, description) {
|
||||
if (!env) {
|
||||
throw new Error('jasmine.Env() required');
|
||||
};
|
||||
if (!suite) {
|
||||
throw new Error('jasmine.Suite() required');
|
||||
};
|
||||
var spec = this;
|
||||
spec.id = env.nextSpecId_++;
|
||||
spec.id = env.nextSpecId ? env.nextSpecId() : null;
|
||||
spec.env = env;
|
||||
spec.suite = suite;
|
||||
spec.description = description;
|
||||
@@ -17,8 +23,8 @@ jasmine.Spec = function(env, suite, description) {
|
||||
spec.afterCallbacks = [];
|
||||
spec.spies_ = [];
|
||||
|
||||
spec.results = new jasmine.NestedResults();
|
||||
spec.results.description = description;
|
||||
spec.results_ = new jasmine.NestedResults();
|
||||
spec.results_.description = description;
|
||||
spec.matchersClass = null;
|
||||
};
|
||||
|
||||
@@ -26,8 +32,18 @@ jasmine.Spec.prototype.getFullName = function() {
|
||||
return this.suite.getFullName() + ' ' + this.description + '.';
|
||||
};
|
||||
|
||||
|
||||
jasmine.Spec.prototype.results = function() {
|
||||
return this.results_;
|
||||
};
|
||||
|
||||
jasmine.Spec.prototype.log = function(message) {
|
||||
return this.results_.log(message);
|
||||
};
|
||||
|
||||
/** @deprecated */
|
||||
jasmine.Spec.prototype.getResults = function() {
|
||||
return this.results;
|
||||
return this.results_;
|
||||
};
|
||||
|
||||
jasmine.Spec.prototype.runs = function (func) {
|
||||
@@ -52,11 +68,8 @@ jasmine.Spec.prototype.expects_that = function(actual) {
|
||||
return this.expect(actual);
|
||||
};
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
jasmine.Spec.prototype.expect = function(actual) {
|
||||
return new (this.getMatchersClass_())(this.env, actual, this.results);
|
||||
return new (this.getMatchersClass_())(this.env, actual, this.results_);
|
||||
};
|
||||
|
||||
jasmine.Spec.prototype.waits = function(timeout) {
|
||||
@@ -71,8 +84,8 @@ jasmine.Spec.prototype.waitsFor = function(timeout, latchFunction, timeoutMessag
|
||||
return this;
|
||||
};
|
||||
|
||||
jasmine.Spec.prototype.failWithException = function (e) {
|
||||
this.results.addResult(new jasmine.ExpectationResult(false, jasmine.util.formatException(e), null));
|
||||
jasmine.Spec.prototype.fail = function (e) {
|
||||
this.results_.addResult(new jasmine.ExpectationResult(false, e ? jasmine.util.formatException(e) : null, null));
|
||||
};
|
||||
|
||||
jasmine.Spec.prototype.getMatchersClass_ = function() {
|
||||
@@ -115,7 +128,7 @@ jasmine.Spec.prototype.after = function(doAfter, test) {
|
||||
jasmine.Spec.prototype.execute = function(onComplete) {
|
||||
var spec = this;
|
||||
if (!spec.env.specFilter(spec)) {
|
||||
spec.results.skipped = true;
|
||||
spec.results_.skipped = true;
|
||||
spec.finish(onComplete);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
*/
|
||||
jasmine.Suite = function(env, description, specDefinitions, parentSuite) {
|
||||
var self = this;
|
||||
self.id = env.nextSuiteId_++;
|
||||
self.id = env.nextSuiteId ? env.nextSuiteId() : null;
|
||||
self.description = description;
|
||||
self.queue = new jasmine.Queue(env);
|
||||
self.parentSuite = parentSuite;
|
||||
@@ -45,8 +45,13 @@ jasmine.Suite.prototype.afterEach = function(afterEachFunction) {
|
||||
this.afterQueue.push(afterEachFunction);
|
||||
};
|
||||
|
||||
/** @deprecated */
|
||||
jasmine.Suite.prototype.getResults = function() {
|
||||
return this.queue.getResults();
|
||||
return this.queue.results();
|
||||
};
|
||||
|
||||
jasmine.Suite.prototype.results = function() {
|
||||
return this.queue.results();
|
||||
};
|
||||
|
||||
jasmine.Suite.prototype.add = function(block) {
|
||||
|
||||
@@ -17,7 +17,7 @@ jasmine.WaitsForBlock.prototype.execute = function (onComplete) {
|
||||
try {
|
||||
latchFunctionResult = self.latchFunction.apply(self.spec);
|
||||
} catch (e) {
|
||||
self.fail(e);
|
||||
self.spec.fail(e);
|
||||
onComplete();
|
||||
return;
|
||||
}
|
||||
@@ -26,7 +26,7 @@ jasmine.WaitsForBlock.prototype.execute = function (onComplete) {
|
||||
onComplete();
|
||||
} else if (self.totalTimeSpentWaitingForLatch >= self.timeout) {
|
||||
var message = 'timed out after ' + self.timeout + ' msec waiting for ' + (self.message || 'something to happen');
|
||||
self.fail({
|
||||
self.spec.fail({
|
||||
name: 'timeout',
|
||||
message: message
|
||||
});
|
||||
|
||||
@@ -323,7 +323,7 @@ jasmine.createSpyObj = function(baseName, methodNames) {
|
||||
};
|
||||
|
||||
jasmine.log = function(message) {
|
||||
jasmine.getEnv().currentSpec.getResults().log(message);
|
||||
jasmine.getEnv().currentSpec.log(message);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user