@applicaster/zapp-react-native-utils
Version:
Applicaster Zapp React Native utilities package
47 lines (33 loc) • 1.31 kB
JavaScript
import * as ReactNative from "react-native";
import NativeDeviceInfo from "react-native/Libraries/Utilities/NativeDeviceInfo";
const mockDimensions = {
window: { width: 1, height: 1 },
screen: { width: 360, height: 540 },
};
const mockDimensionsGet = jest.fn((type) => mockDimensions[type]);
ReactNative.Dimensions.get = mockDimensionsGet;
const { Platform, Dimensions } = ReactNative;
Platform.OS = "android";
const { getInitialDimensions } = require("../getInitialDimensions.native.ts");
describe("useDimensions > helpers ( native )", () => {
beforeEach(() => {
jest.clearAllMocks();
});
it("should call Dimensions.get for window context", () => {
getInitialDimensions("window");
expect(Dimensions.get).toHaveBeenCalled();
});
it("should call Dimensions.get for screen context", () => {
getInitialDimensions("screen");
expect(Dimensions.get).toHaveBeenCalled();
});
it("should call NativeDeviceInfo.getConstants for ios when width === height", () => {
Platform.OS = "ios";
const mockGetConstants = jest
.spyOn(NativeDeviceInfo, "getConstants")
.mockReturnValue({ Dimensions: mockDimensions });
getInitialDimensions("window");
expect(Dimensions.get).toHaveBeenCalled();
expect(mockGetConstants).toHaveBeenCalled();
});
});