UNPKG

@applicaster/zapp-react-native-utils

Version:

Applicaster Zapp React Native utilities package

61 lines (46 loc) 1.48 kB
import * as ReactNative from "react-native"; const mockDimensionsGet = jest.fn( (type) => ({ window: { width: 1, height: 1 }, screen: { width: 360, height: 540 }, })[type] ); ReactNative.Dimensions.get = mockDimensionsGet; const mockGetConstants = jest.fn().mockReturnValue({ Dimensions: { window: { width: 360, height: 540 }, screen: { width: 360, height: 540 }, }, }); jest.mock("react-native/Libraries/Utilities/NativeDeviceInfo", () => ({ getConstants: mockGetConstants, })); 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).toBeCalled(); }); it("should call Dimensions.get for screen context", () => { getInitialDimensions("screen"); expect(Dimensions.get).toBeCalled(); }); it("should call NativeDeviceInfo.getConstants for ios when width === height", () => { Platform.OS = "ios"; jest.fn().mockReturnValue({ Dimensions: { window: { width: 1, height: 1 }, screen: { width: 360, height: 540 }, }, }); getInitialDimensions("window"); expect(Dimensions.get).toBeCalled(); expect(mockGetConstants).toBeCalled(); }); });