Merge branch 'dtychshenko-1740-fail-on-no-expectations'
* Merges #1743 from @dtychshenko * Fixes #1740
This commit is contained in:
@@ -141,12 +141,13 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
this.specDone = function(result) {
|
||||
stateBuilder.specDone(result);
|
||||
|
||||
if (
|
||||
noExpectations(result) &&
|
||||
typeof console !== 'undefined' &&
|
||||
typeof console.error !== 'undefined'
|
||||
) {
|
||||
console.warn("Spec '" + result.fullName + "' has no expectations.");
|
||||
if (noExpectations(result)) {
|
||||
var noSpecMsg = "Spec '" + result.fullName + "' has no expectations.";
|
||||
if (result.status === 'failed') {
|
||||
console.error(noSpecMsg);
|
||||
} else {
|
||||
console.warn(noSpecMsg);
|
||||
}
|
||||
}
|
||||
|
||||
if (!symbols) {
|
||||
@@ -169,7 +170,7 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
};
|
||||
|
||||
this.displaySpecInCorrectFormat = function(result) {
|
||||
return noExpectations(result)
|
||||
return noExpectations(result) && result.status === 'passed'
|
||||
? 'jasmine-empty'
|
||||
: this.resultStatus(result.status);
|
||||
};
|
||||
@@ -392,6 +393,16 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
);
|
||||
}
|
||||
|
||||
if (result.failedExpectations.length === 0) {
|
||||
messages.appendChild(
|
||||
createDom(
|
||||
'div',
|
||||
{ className: 'jasmine-result-message' },
|
||||
'Spec has no expectations'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return failure;
|
||||
}
|
||||
|
||||
@@ -683,9 +694,12 @@ jasmineRequire.HtmlReporter = function(j$) {
|
||||
}
|
||||
|
||||
function noExpectations(result) {
|
||||
var allExpectations =
|
||||
result.failedExpectations.length + result.passedExpectations.length;
|
||||
|
||||
return (
|
||||
result.failedExpectations.length + result.passedExpectations.length ===
|
||||
0 && result.status === 'passed'
|
||||
allExpectations === 0 &&
|
||||
(result.status === 'passed' || result.status === 'failed')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user