@samitouri / QOS-React-2 / commits / 88e59277e7

Added HOC badges to Jest Store serialization

Brian Vaughn committed Jun 7, 2019 at 14:10 UTC 88e59277e7362640bf68799893053f55894e472c
3 files changed +19 -12
src/__tests__/__snapshots__/storeComponentFilters-test.js.snap
+8 -6
@@ -2,9 +2,10 @@
2
3 exports[`Store component filters should filter HOCs: 1: mount 1`] = `
4 [root]
5 - ▾ <Component>
6 - ▾ <Component>
7 - <div>
5 + ▾ <Component> [Bar][Foo]
6 + ▾ <Component> [Foo]
7 + ▾ <Component>
8 + <div>
9 `;
10
11 exports[`Store component filters should filter HOCs: 2: hide all HOCs 1`] = `
@@ -15,9 +16,10 @@ exports[`Store component filters should filter HOCs: 2: hide all HOCs 1`] = `
16
17 exports[`Store component filters should filter HOCs: 3: disable HOC filter 1`] = `
18 [root]
18 - ▾ <Component>
19 - ▾ <Component>
20 - <div>
19 + ▾ <Component> [Bar][Foo]
20 + ▾ <Component> [Foo]
21 + ▾ <Component>
22 + <div>
23 `;
24
25 exports[`Store component filters should filter by display name: 1: mount 1`] = `
src/__tests__/storeComponentFilters-test.js
+5 -5
@@ -170,12 +170,12 @@ describe('Store component filters', () => {
170
171 it('should filter HOCs', () => {
172 const Component = () => <div>Hi</div>;
173 - const WrappedComponent = () => <Component />;
174 - WrappedComponent.displayName = 'withWrapper(Component)';
173 + const Foo = () => <Component />;
174 + Foo.displayName = 'Foo(Component)';
175 + const Bar = () => <Foo />;
176 + Bar.displayName = 'Bar(Foo(Component))';
177
176 - act(() =>
177 - ReactDOM.render(<WrappedComponent />, document.createElement('div'))
178 - );
178 + act(() => ReactDOM.render(<Bar />, document.createElement('div')));
179 expect(store).toMatchSnapshot('1: mount');
180
181 act(() => (store.componentFilters = [utils.createHOCFilter(true)]));
src/__tests__/storeSerializer.js
+6 -1
@@ -22,13 +22,18 @@ export function printElement(element, includeWeight = false) {
22 key = ` key="${element.key}"`;
23 }
24
25 + let hocs = '';
26 + if (element.hocDisplayNames !== null) {
27 + hocs = ` [${element.hocDisplayNames.join('][')}]`;
28 + }
29 +
30 let suffix = '';
31 if (includeWeight) {
32 suffix = ` (${element.isCollapsed ? 1 : element.weight})`;
33 }
34
35 return `${' '.repeat(element.depth + 1)}${prefix} <${element.displayName ||
31 - 'null'}${key}>${suffix}`;
36 + 'null'}${key}>${hocs}${suffix}`;
37 }
38
39 export function printOwnersList(elements, includeWeight = false) {