Merge branch 'dtychshenko-1740-fail-on-no-expectations'

* Merges #1743 from @dtychshenko
* Fixes #1740
This commit is contained in:
Steve Gravrock
2019-09-05 09:48:24 -07:00
11 changed files with 228 additions and 63 deletions
+34 -7
View File
@@ -718,7 +718,7 @@ getJasmineRequireObj().Spec = function(j$) {
return this.asyncExpectationFactory(actual, this);
};
Spec.prototype.execute = function(onComplete, excluded) {
Spec.prototype.execute = function(onComplete, excluded, failSpecWithNoExp) {
var self = this;
var onStart = {
@@ -731,7 +731,7 @@ getJasmineRequireObj().Spec = function(j$) {
var complete = {
fn: function(done) {
self.queueableFn.fn = null;
self.result.status = self.status(excluded);
self.result.status = self.status(excluded, failSpecWithNoExp);
self.resultCallback(self.result, done);
}
};
@@ -802,7 +802,7 @@ getJasmineRequireObj().Spec = function(j$) {
return this.result;
};
Spec.prototype.status = function(excluded) {
Spec.prototype.status = function(excluded, failSpecWithNoExpectations) {
if (excluded === true) {
return 'excluded';
}
@@ -811,11 +811,17 @@ getJasmineRequireObj().Spec = function(j$) {
return 'pending';
}
if (this.result.failedExpectations.length > 0) {
if (
this.result.failedExpectations.length > 0 ||
(failSpecWithNoExpectations &&
this.result.failedExpectations.length +
this.result.passedExpectations.length ===
0)
) {
return 'failed';
} else {
return 'passed';
}
return 'passed';
};
Spec.prototype.getFullName = function() {
@@ -971,6 +977,16 @@ getJasmineRequireObj().Env = function(j$) {
* @default false
*/
failFast: false,
/**
* Whether to fail the spec if it ran no expectations. By default
* a spec that ran no expectations is reported as passed. Setting this
* to true will report such spec as a failure.
* @name Configuration#failSpecWithNoExpectations
* @since 3.5.0
* @type Boolean
* @default false
*/
failSpecWithNoExpectations: false,
/**
* Whether to cause specs to only have one expectation failure.
* @name Configuration#oneFailurePerSpec
@@ -1073,6 +1089,11 @@ getJasmineRequireObj().Env = function(j$) {
config.failFast = configuration.failFast;
}
if (configuration.hasOwnProperty('failSpecWithNoExpectations')) {
config.failSpecWithNoExpectations =
configuration.failSpecWithNoExpectations;
}
if (configuration.hasOwnProperty('oneFailurePerSpec')) {
config.oneFailurePerSpec = configuration.oneFailurePerSpec;
}
@@ -1547,6 +1568,7 @@ getJasmineRequireObj().Env = function(j$) {
tree: topSuite,
runnableIds: runnablesToRun,
queueRunnerFactory: queueRunnerFactory,
failSpecWithNoExpectations: config.failSpecWithNoExpectations,
nodeStart: function(suite, next) {
currentlyExecutingSuites.push(suite);
defaultResourcesForRunnable(suite.id, suite.parentSuite.id);
@@ -7920,6 +7942,7 @@ getJasmineRequireObj().TreeProcessor = function() {
queueRunnerFactory = attrs.queueRunnerFactory,
nodeStart = attrs.nodeStart || function() {},
nodeComplete = attrs.nodeComplete || function() {},
failSpecWithNoExpectations = !!attrs.failSpecWithNoExpectations,
orderChildren =
attrs.orderChildren ||
function(node) {
@@ -8137,7 +8160,11 @@ getJasmineRequireObj().TreeProcessor = function() {
} else {
return {
fn: function(done) {
node.execute(done, stats[node.id].excluded);
node.execute(
done,
stats[node.id].excluded,
failSpecWithNoExpectations
);
}
};
}