Skip to content

Commit 50c46f3

Browse files
committed
test(lists): sanitize snapshots by removing _owner
1 parent 1165571 commit 50c46f3

4 files changed

Lines changed: 555 additions & 382 deletions

File tree

packages/virtualized-lists/Lists/__tests__/VirtualizedList-test.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@ import {format} from 'util';
1616

1717
jest.useFakeTimers();
1818

19+
function removeOwner(obj) {
20+
if (obj === null || typeof obj !== 'object') return obj;
21+
if (Array.isArray(obj)) return obj.map(removeOwner);
22+
23+
const result = {};
24+
for (const key of Object.keys(obj)) {
25+
if (key === '_owner') continue;
26+
result[key] = removeOwner(obj[key]);
27+
}
28+
return result;
29+
}
30+
1931
const skipTestSilenceLinter = it.skip;
2032

2133
describe('VirtualizedList', () => {
@@ -233,7 +245,7 @@ describe('VirtualizedList', () => {
233245
/>,
234246
);
235247
});
236-
expect(component).toMatchSnapshot();
248+
expect(removeOwner(component.toJSON())).toMatchSnapshot();
237249
});
238250

239251
it('test getItem functionality where data is not an Array', async () => {

packages/virtualized-lists/Lists/__tests__/VirtualizedSectionList-test.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ const VirtualizedSectionList = require('../VirtualizedSectionList').default;
1818
const React = require('react');
1919
const ReactTestRenderer = require('react-test-renderer');
2020

21+
function removeOwner(obj) {
22+
if (obj === null || typeof obj !== 'object') return obj;
23+
if (Array.isArray(obj)) return obj.map(removeOwner);
24+
25+
const result = {};
26+
for (const key of Object.keys(obj)) {
27+
if (key === '_owner') continue;
28+
result[key] = removeOwner(obj[key]);
29+
}
30+
return result;
31+
}
32+
2133
describe('VirtualizedSectionList', () => {
2234
it('renders simple list', async () => {
2335
let component;
@@ -122,7 +134,7 @@ describe('VirtualizedSectionList', () => {
122134
/>,
123135
);
124136
});
125-
expect(component).toMatchSnapshot();
137+
expect(removeOwner(component.toJSON())).toMatchSnapshot();
126138
});
127139

128140
it('handles separators correctly', async () => {

0 commit comments

Comments
 (0)