Closed TheOne1006 closed 6 years ago
just came here to find answer for this, couldn't find one so I did it like this:
class ContextProvider extends Component<{}, {}> {
public getChildContext(): any {
return {
contextVariable: 'test'
};
}
public render(): any {
return <div>{this.props.children}</div>;
}
}
expect(
<ContextProvider>
<ComponentUsinContextVariable/>
</ContextProvider>
);
There's an easy module that lets you do just that called preact-context-provider:
import Provider from 'preact-context-provider';
const foo = { some: 'stuff' };
expect(
<Provider foo={foo}>
<App />
</Provider>
);
how set context in test?