@applicaster/quick-brick-core
Version:
Core package for Applicaster's Quick Brick App
71 lines (56 loc) • 1.83 kB
JavaScript
import React from "react";
import { View } from "react-native";
import * as R from "ramda";
import { renderZappApp } from "../index";
const App = () => <View />;
const AppRegistry = {
registerComponent: jest.fn(),
runApplication: jest.fn(),
};
const appMountId = "quick_brick_app";
const APP_COMPONENT_NAME = "QuickBrickApp";
const ERRORS = {
NO_APP_ERROR: "No App Component provided, nothing to render",
NO_RENDERER_ERROR:
"No Renderer provided - you need to pass React Native's AppRegistry module",
NO_MOUNT_ID: "You need to provide the id of the mount node",
};
global.document = {
getElementById: R.identity,
};
describe("renderZappApp", () => {
beforeEach(() => {
AppRegistry.registerComponent.mockClear();
AppRegistry.runApplication.mockClear();
});
it("throws an error if no App is provided", () => {
expect(() => renderZappApp({})).toThrow(ERRORS.NO_APP_ERROR);
});
it("throws an error if no renderer is provided", () => {
expect(() => renderZappApp({ App })).toThrow(ERRORS.NO_RENDERER_ERROR);
});
describe("when using the react-native renderer", () => {
it("renders the app", () => {
renderZappApp({ App, AppRegistry });
expect(AppRegistry.registerComponent).toHaveBeenCalledWith(
APP_COMPONENT_NAME,
expect.any(Function)
);
});
});
describe("when using the AppRegistry renderer for web", () => {
it("renders the app", () => {
renderZappApp({ App, AppRegistry, appMountId });
expect(AppRegistry.registerComponent).toHaveBeenCalledWith(
APP_COMPONENT_NAME,
expect.any(Function)
);
expect(AppRegistry.runApplication).toHaveBeenCalledWith(
APP_COMPONENT_NAME,
{
rootTag: document.getElementById(appMountId),
}
);
});
});
});