Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sorted object diff to improve failure output (fixes issue #206) #208

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions qunit/qunit.js
Original file line number Diff line number Diff line change
Expand Up @@ -1401,8 +1401,15 @@ QUnit.jsDump = (function() {
object:function( map, stack ) {
var ret = [ ];
QUnit.jsDump.up();
for ( var key in map ) {
var val = map[key];
if (Object.keys) {
var keys = Object.keys(map);
} else {
keys = [];
for (var key in map) { keys.push(key); }
}
keys.sort();
for (var i = 0; i < keys.length; i++) {
var key = keys[i], val = map[key];
ret.push( QUnit.jsDump.parse(key,'key') + ': ' + QUnit.jsDump.parse(val, undefined, stack));
}
QUnit.jsDump.down();
Expand Down
8 changes: 4 additions & 4 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ test("makeurl working with settings from testEnvironment", function() {
module("jsDump");
test("jsDump output", function() {
equal( QUnit.jsDump.parse([1, 2]), "[\n 1,\n 2\n]" );
equal( QUnit.jsDump.parse({top: 5, left: 0}), "{\n \"top\": 5,\n \"left\": 0\n}" );
equal( QUnit.jsDump.parse({top: 5, left: 0}), "{\n \"left\": 0,\n \"top\": 5\n}" );
if (typeof document !== 'undefined' && document.getElementById("qunit-header")) {
equal( QUnit.jsDump.parse(document.getElementById("qunit-header")), "<h1 id=\"qunit-header\"></h1>" );
equal( QUnit.jsDump.parse(document.getElementsByTagName("h1")), "[\n <h1 id=\"qunit-header\"></h1>\n]" );
Expand Down Expand Up @@ -354,15 +354,15 @@ test("check jsDump recursion", function() {

var noref = chainwrap(0);
var nodump = QUnit.jsDump.parse(noref);
equal(nodump, '{\n "wrap": undefined,\n "first": true\n}');
equal(nodump, '{\n "first": true,\n "wrap": undefined\n}');

var selfref = chainwrap(1);
var selfdump = QUnit.jsDump.parse(selfref);
equal(selfdump, '{\n "wrap": recursion(-1),\n "first": true\n}');
equal(selfdump, '{\n "first": true,\n "wrap": recursion(-1)\n}');

var parentref = chainwrap(2);
var parentdump = QUnit.jsDump.parse(parentref);
equal(parentdump, '{\n "wrap": {\n "wrap": recursion(-2),\n "first": true\n }\n}');
equal(parentdump, '{\n "wrap": {\n "first": true,\n "wrap": recursion(-2)\n }\n}');

var circref = chainwrap(10);
var circdump = QUnit.jsDump.parse(circref);
Expand Down