Added HOC filter test
Brian Vaughn committed
Jun 7, 2019 at 14:06 UTC
21bb66a8c7d96a5af7176a766fc59ddcb30ba676
3 files changed
+60
-12
src/__tests__/__snapshots__/storeComponentFilters-test.js.snap
+20
@@ -1,5 +1,25 @@
1
// Jest Snapshot v1, https://goo.gl/fbAQLP
2
3
+exports[`Store component filters should filter HOCs: 1: mount 1`] = `
4
+[root]
5
+ ▾ <Component>
6
+ ▾ <Component>
7
+ <div>
8
+`;
9
+
10
+exports[`Store component filters should filter HOCs: 2: hide all HOCs 1`] = `
11
+[root]
12
+ ▾ <Component>
13
+ <div>
14
+`;
15
+
16
+exports[`Store component filters should filter HOCs: 3: disable HOC filter 1`] = `
17
+[root]
18
+ ▾ <Component>
19
+ ▾ <Component>
20
+ <div>
21
+`;
22
+
23
exports[`Store component filters should filter by display name: 1: mount 1`] = `
24
[root]
25
▾ <Foo>
src/__tests__/storeComponentFilters-test.js
+19
@@ -167,4 +167,23 @@ describe('Store component filters', () => {
167
168
expect(store).toMatchSnapshot('3: hide components in a made up fake path');
169
});
170
+
171
+ it('should filter HOCs', () => {
172
+ const Component = () => <div>Hi</div>;
173
+ const WrappedComponent = () => <Component />;
174
+ WrappedComponent.displayName = 'withWrapper(Component)';
175
+
176
+ act(() =>
177
+ ReactDOM.render(<WrappedComponent />, document.createElement('div'))
178
+ );
179
+ expect(store).toMatchSnapshot('1: mount');
180
+
181
+ act(() => (store.componentFilters = [utils.createHOCFilter(true)]));
182
+
183
+ expect(store).toMatchSnapshot('2: hide all HOCs');
184
+
185
+ act(() => (store.componentFilters = [utils.createHOCFilter(false)]));
186
+
187
+ expect(store).toMatchSnapshot('3: disable HOC filter');
188
+ });
189
});
src/__tests__/utils.js
+21
-12
@@ -60,18 +60,6 @@ export function beforeEachProfiling(): void {
60
);
61
}
62
63
-export function createElementTypeFilter(
64
- elementType: ElementType,
65
- isEnabled: boolean = true
66
-) {
67
- const Types = require('src/types');
68
- return {
69
- type: Types.ComponentFilterElementType,
70
- isEnabled,
71
- value: elementType,
72
- };
73
-}
74
-
63
export function createDisplayNameFilter(
64
source: string,
65
isEnabled: boolean = true
@@ -91,6 +79,27 @@ export function createDisplayNameFilter(
79
};
80
}
81
82
+export function createHOCFilter(isEnabled: boolean = true) {
83
+ const Types = require('src/types');
84
+ return {
85
+ type: Types.ComponentFilterHOC,
86
+ isEnabled,
87
+ isValid: true,
88
+ };
89
+}
90
+
91
+export function createElementTypeFilter(
92
+ elementType: ElementType,
93
+ isEnabled: boolean = true
94
+) {
95
+ const Types = require('src/types');
96
+ return {
97
+ type: Types.ComponentFilterElementType,
98
+ isEnabled,
99
+ value: elementType,
100
+ };
101
+}
102
+
103
export function createLocationFilter(
104
source: string,
105
isEnabled: boolean = true