@applicaster/zapp-react-native-utils
Version:
Applicaster Zapp React Native utilities package
33 lines (22 loc) • 917 B
JavaScript
/* eslint-disable react/prop-types */
import * as React from "react";
import { render } from "@testing-library/react-native";
import { View } from "react-native";
import { createWithConsumerDecorator } from "../withConsumer";
import { ReactContext, mockContextData } from "./fixtures";
describe("createConsumer", () => {
const { Consumer } = ReactContext;
const withConsumer = createWithConsumerDecorator(Consumer);
it("creates a context consumer function", () => {
expect(withConsumer).toBeFunction();
const newContextValue = "newValue";
const Child = (props) => {
props.setContext(newContextValue);
return <View>{props.context}</View>;
};
const DecoratedChild = withConsumer(Child);
const wrapper = render(<DecoratedChild />);
expect(wrapper.toJSON()).toMatchSnapshot();
expect(mockContextData.setContext).toHaveBeenCalledWith(newContextValue);
});
});