Specs without expectations should be alerted to the user

- Add console.error to the HtmlReporter when there is a spec without any expectation
- Change the spec's link text and color to include a warning
- Create a status for specs to label them as "empty"
- console is not accessible to IE unless you have developer tools open,
  so protect against that by mocking console.

[#59424794]
This commit is contained in:
Christopher Amavisca, Greg Cobb and Luan Santos
2014-03-10 11:19:07 -07:00
parent 71dbffeaef
commit 1922514f2d
8 changed files with 107 additions and 7 deletions

View File

@@ -95,6 +95,10 @@ jasmineRequire.HtmlReporter = function(j$) {
var failures = [];
this.specDone = function(result) {
if(result.status == 'empty' && console && console.error) {
console.error('Spec \'' + result.fullName + '\' has no expectations.');
}
if (result.status != 'disabled') {
specsExecuted++;
}
@@ -189,12 +193,16 @@ jasmineRequire.HtmlReporter = function(j$) {
specListNode = createDom('ul', {className: 'specs'});
domParent.appendChild(specListNode);
}
var specDescription = resultNode.result.description;
if(resultNode.result.status == 'empty') {
specDescription = 'SPEC HAS NO EXPECTATIONS ' + specDescription;
}
specListNode.appendChild(
createDom('li', {
className: resultNode.result.status,
id: 'spec-' + resultNode.result.id
},
createDom('a', {href: specHref(resultNode.result)}, resultNode.result.description)
createDom('a', {href: specHref(resultNode.result)}, specDescription)
)
);
}

View File

@@ -43,6 +43,7 @@ body { background-color: #eeeeee; padding: 0; margin: 5px; overflow-y: scroll; }
.html-reporter .summary ul.suite { margin-top: 7px; margin-bottom: 7px; }
.html-reporter .summary li.passed a { color: #007069; }
.html-reporter .summary li.failed a { color: #ca3a11; }
.html-reporter .summary li.empty a { color: #ba9d37; }
.html-reporter .summary li.pending a { color: #ba9d37; }
.html-reporter .description + .suite { margin-top: 0; }
.html-reporter .suite { margin-top: 14px; }

View File

@@ -242,6 +242,7 @@ getJasmineRequireObj().Spec = function(j$) {
this.expectationResultFactory = attrs.expectationResultFactory || function() { };
this.queueRunnerFactory = attrs.queueRunnerFactory || function() {};
this.catchingExceptions = attrs.catchingExceptions || function() { return true; };
this.expectCalled = false;
if (!this.fn) {
this.pend();
@@ -256,6 +257,7 @@ getJasmineRequireObj().Spec = function(j$) {
}
Spec.prototype.addExpectationResult = function(passed, data) {
this.expectCalled = true;
if (passed) {
return;
}
@@ -327,6 +329,10 @@ getJasmineRequireObj().Spec = function(j$) {
return 'pending';
}
if(!this.expectCalled) {
return 'empty';
}
if (this.result.failedExpectations.length > 0) {
return 'failed';
} else {