Skip to content

Commit

Permalink
Remove context logic
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinweber committed Feb 18, 2022
1 parent 829fae4 commit 7d7790d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 32 deletions.
7 changes: 1 addition & 6 deletions src/RootFinder.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { Component } from 'preact';

export default class RootFinder extends Component<{ context: any }> {
// I'm not sure if this is needed… It might help with legacy context 🤷
getChildContext() {
return this.props.context;
}

export default class RootFinder extends Component {
render() {
return this.props.children;
}
Expand Down
10 changes: 2 additions & 8 deletions src/wrapWithWrappingComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default function wrapWithWrappingComponent(
node: ReactElement,
options: ShallowRendererProps = {}
) {
const { wrappingComponent, wrappingComponentProps = {}, context } = options;
const { wrappingComponent, wrappingComponentProps = {} } = options;

if (!wrappingComponent) {
return node;
Expand All @@ -24,15 +24,9 @@ export default function wrapWithWrappingComponent(
nodeWithValidChildren.props.children = childElements(nodeWithValidChildren);
}

const rootFinderContext =
(wrappingComponentProps as { context: any })?.context || context;
const rootFinderProps = rootFinderContext
? { context: rootFinderContext }
: null;

return createElement(
wrappingComponent,
wrappingComponentProps,
createElement(RootFinder, rootFinderProps, nodeWithValidChildren)
createElement(RootFinder, null, nodeWithValidChildren)
);
}
21 changes: 3 additions & 18 deletions test/integration_test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -523,37 +523,22 @@ describe('integration tests', () => {
);
});

it('passes context option to RootFinder', () => {
function Component() {
return <span>test</span>;
}
const wrapper = shallow(<Component />, {
wrappingComponent: WrappingComponent,
context: { test: 'abc' },
});

const output = debugWrappedComponent(wrapper);
assert.equal(
output,
'<div><RootFinder context={{...}}><Component /></RootFinder></div>'
);
});

it('passes wrappingComponentProps.context option to wrappingComponent and RootFinder', () => {
it('passes wrappingComponentProps to wrappingComponent', () => {
function Component() {
return <span>test</span>;
}
const wrapper = shallow(<Component />, {
wrappingComponent: WrappingComponent,
wrappingComponentProps: {
foo: 'bar',
context: { test: 'abc' },
},
});

const output = debugWrappedComponent(wrapper);
assert.equal(
output,
'<div context={{...}}><RootFinder context={{...}}><Component /></RootFinder></div>'
'<div foo="bar" context={{...}}><RootFinder><Component /></RootFinder></div>'
);
});

Expand Down

0 comments on commit 7d7790d

Please sign in to comment.