UNPKG

@applicaster/zapp-react-native-utils

Version:

Applicaster Zapp React Native utilities package

33 lines (24 loc) 1.01 kB
/* eslint-disable react/prop-types */ import * as React from "react"; import { shallow } from "enzyme"; import toJson from "enzyme-to-json"; import { View } from "react-native"; import { createWithConsumerDecorator } from "../withConsumer"; import { ReactContext, mockContextData } from "./fixtures"; describe("createConsumer", () => { const { Consumer } = ReactContext; const withConsumer = createWithConsumerDecorator(Consumer); it("returns a function", () => { expect(withConsumer).toBeFunction(); }); it("creates a context consumer function", () => { const Child = (props) => <View>{props.context}</View>; const DecoratedChild = withConsumer(Child); const newContextValue = "newValue"; const wrapper = shallow(<DecoratedChild />); const childWrapper = wrapper.dive(); expect(toJson(childWrapper)).toMatchSnapshot(); childWrapper.props().setContext(newContextValue); expect(mockContextData.setContext).toHaveBeenCalledWith(newContextValue); }); });