Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('render one Consumer use default context value', function() {
const ThemeContext = createContext('light');
function MyContext() {
return (
);
};
function MyContext2() {
return (
{value => <div>{value}</div>}
);
}
it('render with context hook', () => {
const NumberContext = createContext(5);
function MyComponent() {
const value = useContext(NumberContext);
return (
<div>The answer is {value}.</div>
);
};
let str = renderToString();
expect(str).toBe('<div>The answer is 5.</div>');
});
it('multiple contexts', () => {
const Theme = createContext('dark');
const Language = createContext('french');
class Parent extends Component {
render() {
return (
);
}
}
function Child() {
return (
it('nested context unwinding', () => {
const Theme = createContext('dark');
const Language = createContext('french');
const App = () => (
<div>
{theme => <div id="theme1">{theme}</div>}
{theme => <div id="theme2">{theme}</div>}
</div>
it('function context', () => {
let Ctx = createContext();
function Provider() {
return (
{this.props.children}
);
}
function FnConsumer() {
return useContext(Ctx);
}
const str = renderToString(
<span></span>
it('render with Context.Provider', () => {
const ThemeContext = createContext('light');
function MyContext() {
return (
);
};
function MyComponent() {
const value = useContext(ThemeContext);
return (
<div>Current theme is {value}.</div>
);
};
beforeEach(() => {
Context = createContext('none');
class Parent extends Component {
render() {
return (
{this.props.children}
);
}
}
Consumer = Context.Consumer;
PurpleContextProvider = props => (
{props.children}
);
RedContextProvider = props => (
{props.children}