Skip to content

Commit

Permalink
fix "TypeError: Converting circular structure to JSON" for failed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cherniavskii committed Aug 23, 2022
1 parent f5abc74 commit cd16a06
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ describe('<DataGridPro /> - Row pinning', () => {
<BaselineTestCase rowCount={2} colCount={1} rows={[]} getRowClassName={() => className} />,
);

expect(getRowById(0)!.classList.contains(className)).to.equal(true);
expect(getRowById(1)!.classList.contains(className)).to.equal(true);
expect(getRowById(0)!).to.have.class(className);
expect(getRowById(1)!).to.have.class(className);
});
});
21 changes: 21 additions & 0 deletions test/karma.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,27 @@ import { unstable_resetCreateSelectorCache } from '@mui/x-data-grid/internals';
const packagesContext = require.context('../packages', true, /\.test\.tsx$/);
packagesContext.keys().forEach(packagesContext);

// See https://github.com/mui/mui-x/pull/3607#discussion_r784785626
const jsonStringify = JSON.stringify;
JSON.stringify = (val) =>
jsonStringify(
val,
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cyclic_object_value
() => {
const seen = new WeakSet();
return (key, value) => {
if (typeof value === 'object' && value !== null) {
if (seen.has(value)) {
return '[seen]';
}
seen.add(value);
}
return value;
};
},
2,
);

afterEach(function afterEach() {
unstable_resetCleanupTracking();
unstable_resetCreateSelectorCache();
Expand Down

0 comments on commit cd16a06

Please sign in to comment.