Added support for ES6 sets to toContain and toEqual.

This commit is contained in:
Erik Welander
2016-03-04 01:59:10 -08:00
parent 1da6c7cf85
commit 927cc011d6
5 changed files with 96 additions and 0 deletions

View File

@@ -30,6 +30,8 @@ getJasmineRequireObj().pp = function(j$) {
this.emitScalar('HTMLNode');
} else if (value instanceof Date) {
this.emitScalar('Date(' + value + ')');
} else if (value.toString && value.toString() == '[object Set]') {
this.emitSet(value);
} else if (value.toString && typeof value === 'object' && !(value instanceof Array) && value.toString !== Object.prototype.toString) {
this.emitScalar(value.toString());
} else if (j$.util.arrayContains(this.seen, value)) {
@@ -59,6 +61,7 @@ getJasmineRequireObj().pp = function(j$) {
};
PrettyPrinter.prototype.emitArray = j$.unimplementedMethod_;
PrettyPrinter.prototype.emitSet = j$.unimplementedMethod_;
PrettyPrinter.prototype.emitObject = j$.unimplementedMethod_;
PrettyPrinter.prototype.emitScalar = j$.unimplementedMethod_;
PrettyPrinter.prototype.emitString = j$.unimplementedMethod_;
@@ -115,6 +118,26 @@ getJasmineRequireObj().pp = function(j$) {
this.append(' ]');
};
StringPrettyPrinter.prototype.emitSet = function(set) {
if (this.ppNestLevel_ > j$.MAX_PRETTY_PRINT_DEPTH) {
this.append('Set');
return;
}
this.append('Set( ');
var size = Math.min(set.size, j$.MAX_PRETTY_PRINT_SET_SIZE);
var iter = set.values();
for (var i = 0; i < size; i++) {
if (i > 0) {
this.append(', ');
}
this.format(iter.next().value);
}
if (set.size > size){
this.append(', ...');
}
this.append(' )');
};
StringPrettyPrinter.prototype.emitObject = function(obj) {
var constructorName = obj.constructor ? j$.fnNameFor(obj.constructor) : 'null';
this.append(constructorName);