@applicaster/quick-brick-core
Version:
Core package for Applicaster's Quick Brick App
69 lines (54 loc) • 1.58 kB
JavaScript
import * as React from "react";
import { View, Text } from "react-native";
import { render } from "@testing-library/react-native";
import { remoteContextReloader } from "../index";
import * as ContextReloader from "../getRemoteContextData";
const spy = jest.spyOn(ContextReloader, "getRemoteContextData");
spy.mockImplementation(() => jest.fn());
const Component = () => (
<View>
<Text>I'm a component</Text>
</View>
);
const appSettings = {
runtimeConfigurationUrls: { foo: "bar" },
};
const plugins = [];
const dispatch = jest.fn();
describe("remoteContextReloader", () => {
const WrappedComponent = remoteContextReloader(Component);
let rendered;
beforeEach(() => {
rendered = render(
<WrappedComponent {...{ appSettings, plugins, dispatch }} />
);
});
afterEach(() => {
jest.clearAllMocks();
});
it("calls componentDidMount and renders correctly", () => {
const { getByText } = rendered;
expect(getByText("I'm a component")).toBeTruthy();
});
describe("when in __DEV__", () => {
beforeAll(() => {
global.__DEV__ = true;
global.process.env.ENABLE_REMOTE_DATA_IN_DEV = "false";
});
it("doesn't invoke the context reloader", () => {
expect(spy).not.toHaveBeenCalled();
});
});
describe("when not in __DEV__", () => {
beforeAll(() => {
global.__DEV__ = false;
});
it("invokes the context reloader", () => {
expect(spy).toHaveBeenCalledWith(
dispatch,
appSettings.runtimeConfigurationUrls,
plugins
);
});
});
});