@applicaster/quick-brick-core
Version:
Core package for Applicaster's Quick Brick App
79 lines (61 loc) • 1.98 kB
JavaScript
import * as React from "react";
import { View, Text } from "react-native";
import { shallow } from "enzyme";
import { shallowToJson } from "enzyme-to-json";
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);
afterEach(() => {
jest.clearAllMocks();
});
it("adds a componentDidMount method", () => {
const wrapper = shallow(
<WrappedComponent {...{ appSettings, plugins, dispatch }} />
);
expect(shallowToJson(wrapper)).toMatchSnapshot();
expect(wrapper.instance()).toHaveProperty("componentDidMount");
expect(wrapper.instance().componentDidMount).toBeFunction();
});
describe("when in __DEV__", () => {
beforeAll(() => {
global.__DEV__ = true;
global.process.env.ENABLE_REMOTE_DATA_IN_DEV = "false";
});
it("doesn't invoke the context reloader", () => {
const wrapper = shallow(
<WrappedComponent {...{ appSettings, plugins, dispatch }} />
);
expect(shallowToJson(wrapper)).toMatchSnapshot();
expect(spy).not.toHaveBeenCalled();
});
});
describe("when not in __DEV__", () => {
beforeAll(() => {
global.__DEV__ = false;
});
it("invokes the context reloader", () => {
const wrapper = shallow(
<WrappedComponent {...{ appSettings, plugins, dispatch }} />
);
expect(shallowToJson(wrapper)).toMatchSnapshot();
expect(spy).toHaveBeenCalledWith(
dispatch,
appSettings.runtimeConfigurationUrls,
plugins
);
});
});
});