Skip to content

Commit

Permalink
Set maxDepth to truncate extraordinarily deep object printing (jestjs…
Browse files Browse the repository at this point in the history
…#2078)

* Set maxDepth to fix infinite recursion for HTMLElements

This change is based on the feedback from @cpojer in jamiebuilds/pretty-format#47.

* Add an integration test to verify non-crashing
  • Loading branch information
Evan Scott authored and nickpresta committed Nov 15, 2016
1 parent cb0fe3b commit 6b87f6d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
21 changes: 21 additions & 0 deletions integration_tests/__tests__/compare-dom-nodes-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @emails oncall+jsinfra
*/
'use strict';

const runJest = require('../runJest');
const skipOnWindows = require('skipOnWindows');

skipOnWindows.suite();

test('does not crash when expect involving a DOM node fails', () => {
const result = runJest('compare-dom-nodes');

expect(result.stderr).toContain('FAIL __tests__/failed-assertion.js');
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test('a failed assertion comparing a DOM node does not crash Jest', () => {
expect(document.body).toBe(null);
});
6 changes: 6 additions & 0 deletions integration_tests/compare-dom-nodes/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"jest": {
"automock": true,
"testEnvironment": "jsdom"
}
}
2 changes: 2 additions & 0 deletions packages/jest-matcher-utils/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,13 @@ const getType = (value: any): ValueType => {
const stringify = (object: any): string => {
try {
return prettyFormat(object, {
maxDepth: 10,
min: true,
});
} catch (e) {
return prettyFormat(object, {
callToJSON: false,
maxDepth: 10,
min: true,
});
}
Expand Down

0 comments on commit 6b87f6d

Please sign in to comment.