Compare commits

...

4 Commits

Author SHA1 Message Date
Lee Byrd & Christian Williams a5926d22a1 Use pretty dom printing. 2010-06-24 11:58:57 -07:00
Lee Byrd & Christian Williams 25f57c3321 Fix example_runner.html to call env.addReporter rather that set env.reporter directly. 2010-06-24 11:32:22 -07:00
Christian Williams 3d66c5f051 Styling. 2010-06-24 11:19:21 -07:00
Christian Williams 9384512138 Old rev. 2010-06-24 11:19:12 -07:00
5 changed files with 131 additions and 5 deletions

View File

@ -12,7 +12,7 @@
<body>
<script type="text/javascript">
var jasmineEnv = jasmine.getEnv();
jasmineEnv.reporter = new jasmine.TrivialReporter();
jasmineEnv.addReporter(jasmine.TrivialReporter());
jasmineEnv.execute();
</script>

View File

@ -2,6 +2,7 @@ jasmine.TrivialReporter = function(doc) {
this.document = doc || document;
this.suiteDivs = {};
this.logRunningSpecs = false;
this.domPrettyPrint = false;
};
jasmine.TrivialReporter.prototype.createDom = function(type, attrs, childrenVarArgs) {
@ -145,7 +146,7 @@ jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) {
if (result.type == 'log') {
messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage log'}, result.toString()));
} else if (result.type == 'expect' && result.passed && !result.passed()) {
messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage fail'}, result.message));
messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage fail'}, this.reportWhatever(result)));
if (result.trace.stack) {
messagesDiv.appendChild(this.createDom('div', {className: 'stackTrace'}, result.trace.stack));
@ -160,6 +161,31 @@ jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) {
this.suiteDivs[spec.suite.id].appendChild(specDiv);
};
jasmine.TrivialReporter.prototype.reportWhatever = function(result) {
if (this.domPrettyPrint) {
var actualDiv, expectedDiv;
var matcherString = result.matcherName;
var table = this.createDom('table', {},
this.createDom('tr', {},
this.createDom('td', {colspan: 2}, result.message)),
this.createDom('tr', {},
this.createDom('th', {}, 'expect()'),
this.createDom('th', {}, matcherString + "()")),
this.createDom('tr', {},
actualDiv = this.createDom('td'),
expectedDiv = this.createDom('td'))
);
new jasmine.HtmlPrettyPrinter(actualDiv).format(result.actual);
new jasmine.HtmlPrettyPrinter(expectedDiv).format(result.expected);
return table;
} else {
return result.message;
}
};
jasmine.TrivialReporter.prototype.log = function() {
var console = jasmine.getGlobal().console;
if (console && console.log) console.log.apply(console, arguments);
@ -180,3 +206,61 @@ jasmine.TrivialReporter.prototype.specFilter = function(spec) {
if (!paramMap["spec"]) return true;
return spec.getFullName().indexOf(paramMap["spec"]) == 0;
};
jasmine.HtmlPrettyPrinter = function(el) {
jasmine.PrettyPrinter.call(this);
this.el = el;
};
jasmine.util.inherit(jasmine.HtmlPrettyPrinter, jasmine.PrettyPrinter);
jasmine.HtmlPrettyPrinter.prototype.createDom = jasmine.FancyHtmlReporter.prototype.createDom;
jasmine.HtmlPrettyPrinter.prototype.emitScalar = function(value) {
this.append(this.createDom('pre', {}, value));
};
jasmine.HtmlPrettyPrinter.prototype.emitString = function(value) {
this.append(this.createDom('pre', {className: 'string'}, value));
};
jasmine.HtmlPrettyPrinter.prototype.emitArray = function(array) {
var table = this.createDom('table', {className: 'array'});
for (var i = 0; i < array.length; i++) {
var oldEl = this.el;
this.el = this.createDom('td');
table.appendChild(this.createDom('tr', {}, this.el));
this.format(array[i]);
this.el = oldEl;
}
this.append(table);
};
jasmine.HtmlPrettyPrinter.prototype.emitObject = function(obj) {
var self = this;
var table = this.createDom('table', {className: 'object'});
this.iterateObject(obj, function(property, isGetter) {
var tr = self.createDom('tr');
table.appendChild(tr);
tr.appendChild(self.createDom('th', {}, property));
var oldEl = self.el;
self.el = self.createDom('td');
tr.appendChild(self.createDom('th', {}, self.el));
if (isGetter) {
self.el.appendChild(self.createDom('pre', {className: 'getter'}, '<getter>'));
} else {
self.format(obj[property]);
}
self.el = oldEl;
});
this.append(table);
};
jasmine.HtmlPrettyPrinter.prototype.append = function(element) {
this.el.appendChild(element);
};

View File

@ -131,6 +131,38 @@ body {
color: black;
}
.resultMessage > table {
background-color: white;
width: 100%;
font-size: .8em;
padding: .5em;
margin: .5em;
border: 1px solid black;
}
.resultMessage > table > tr > th, .resultMessage > table > tr > td {
text-align: left;
width: 50%;
padding: 0;
margin: 0;
}
.resultMessage td {
vertical-align: top;
border: 1px inset;
}
.resultMessage pre {
margin: 0;
}
.resultMessage .object, .resultMessage .array {
}
.resultMessage .string {
font-style: italic;
}
.stackTrace {
white-space: pre;
font-size: .8em;

View File

@ -59,12 +59,13 @@
var jasmineEnv = jasmine.getEnv();
jasmineEnv.updateInterval = 1000;
var trivialReporter = new jasmine.TrivialReporter();
var reporter = new jasmine.TrivialReporter();
reporter.domPrettyPrint = true;
jasmineEnv.addReporter(trivialReporter);
jasmineEnv.addReporter(reporter);
jasmineEnv.specFilter = function(spec) {
return trivialReporter.specFilter(spec);
return reporter.specFilter(spec);
};
window.onload = function() {

View File

@ -155,6 +155,15 @@ describe("TrivialReporter", function() {
var errorDiv = findElement(divs, 'resultMessage fail');
expect(errorDiv.innerHTML).toEqual("Expected '1 &lt; 2' to &lt;b&gt;e null, &amp; it was not");
});
xit("should not look weird", function() {
expect(123).toBeLessThan(121);
expect(jasmine.createSpy("uncalled spy")).toHaveBeenCalled();
expect(jasmine.createSpy("uncalled spy")).toHaveBeenCalledWith(123, 456);
expect(true).not.toEqual(true);
});
});
describe("log messages", function() {