Added HOC filter test

This commit is contained in:
Brian Vaughn
2019-06-07 14:06:08 -07:00
parent 956935f915
commit 21bb66a8c7
3 changed files with 60 additions and 12 deletions
@@ -1,5 +1,25 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Store component filters should filter HOCs: 1: mount 1`] = `
[root]
▾ <Component>
▾ <Component>
<div>
`;
exports[`Store component filters should filter HOCs: 2: hide all HOCs 1`] = `
[root]
▾ <Component>
<div>
`;
exports[`Store component filters should filter HOCs: 3: disable HOC filter 1`] = `
[root]
▾ <Component>
▾ <Component>
<div>
`;
exports[`Store component filters should filter by display name: 1: mount 1`] = `
[root]
▾ <Foo>
@@ -167,4 +167,23 @@ describe('Store component filters', () => {
expect(store).toMatchSnapshot('3: hide components in a made up fake path');
});
it('should filter HOCs', () => {
const Component = () => <div>Hi</div>;
const WrappedComponent = () => <Component />;
WrappedComponent.displayName = 'withWrapper(Component)';
act(() =>
ReactDOM.render(<WrappedComponent />, document.createElement('div'))
);
expect(store).toMatchSnapshot('1: mount');
act(() => (store.componentFilters = [utils.createHOCFilter(true)]));
expect(store).toMatchSnapshot('2: hide all HOCs');
act(() => (store.componentFilters = [utils.createHOCFilter(false)]));
expect(store).toMatchSnapshot('3: disable HOC filter');
});
});
+21 -12
View File
@@ -60,18 +60,6 @@ export function beforeEachProfiling(): void {
);
}
export function createElementTypeFilter(
elementType: ElementType,
isEnabled: boolean = true
) {
const Types = require('src/types');
return {
type: Types.ComponentFilterElementType,
isEnabled,
value: elementType,
};
}
export function createDisplayNameFilter(
source: string,
isEnabled: boolean = true
@@ -91,6 +79,27 @@ export function createDisplayNameFilter(
};
}
export function createHOCFilter(isEnabled: boolean = true) {
const Types = require('src/types');
return {
type: Types.ComponentFilterHOC,
isEnabled,
isValid: true,
};
}
export function createElementTypeFilter(
elementType: ElementType,
isEnabled: boolean = true
) {
const Types = require('src/types');
return {
type: Types.ComponentFilterElementType,
isEnabled,
value: elementType,
};
}
export function createLocationFilter(
source: string,
isEnabled: boolean = true