Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit 1aac162

Browse files
committed
added tests
1 parent f68bbf9 commit 1aac162

File tree

4 files changed

+114
-43
lines changed

4 files changed

+114
-43
lines changed

__tests__/index.unit.test.ts

Lines changed: 0 additions & 42 deletions
This file was deleted.

__tests__/index.unit.test.tsx

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
import React from "react";
2+
import {
3+
responsiveHeight,
4+
responsiveWidth,
5+
responsiveFontSize,
6+
responsiveScreenHeight,
7+
responsiveScreenWidth,
8+
responsiveScreenFontSize,
9+
useResponsiveHeight,
10+
useResponsiveWidth,
11+
useResponsiveFontSize,
12+
useResponsiveScreenHeight,
13+
useResponsiveScreenWidth,
14+
useResponsiveScreenFontSize
15+
} from "../lib/index";
16+
import { render, cleanup } from "@testing-library/react-native";
17+
18+
afterEach(cleanup);
19+
20+
describe("Testing common utils", () => {
21+
it("responsiveHeight", () => {
22+
const height = responsiveHeight(20);
23+
expect(height).toBe(20);
24+
});
25+
26+
it("responsiveWidth", () => {
27+
const width = responsiveWidth(20);
28+
expect(width).toBe(20);
29+
});
30+
31+
it("responsiveFontSize", () => {
32+
const fontSize = responsiveFontSize(2);
33+
expect(fontSize).toBe(4.0794577223746264);
34+
});
35+
36+
it("responsiveScreenHeight", () => {
37+
const height = responsiveScreenHeight(20);
38+
expect(height).toBe(20);
39+
});
40+
41+
it("responsiveScreenWidth", () => {
42+
const width = responsiveScreenWidth(20);
43+
expect(width).toBe(20);
44+
});
45+
46+
it("responsiveScreenFontSize", () => {
47+
const fontSize = responsiveScreenFontSize(2);
48+
expect(fontSize).toBe(4.0794577223746264);
49+
});
50+
});
51+
52+
export interface IDimensionsData {
53+
window: {
54+
height: number;
55+
width: number;
56+
fontSize: number;
57+
};
58+
screen: {
59+
height: number;
60+
width: number;
61+
fontSize: number;
62+
};
63+
}
64+
65+
const useDimensionHooks = (): IDimensionsData => {
66+
return {
67+
window: {
68+
height: useResponsiveHeight(20),
69+
width: useResponsiveWidth(20),
70+
fontSize: useResponsiveFontSize(2)
71+
},
72+
screen: {
73+
height: useResponsiveScreenHeight(20),
74+
width: useResponsiveScreenWidth(20),
75+
fontSize: useResponsiveScreenFontSize(2)
76+
}
77+
};
78+
};
79+
80+
const HookRenderer = ({
81+
children
82+
}: {
83+
children: (arg: IDimensionsData) => any;
84+
}) => {
85+
const dimensionsData = useDimensionHooks();
86+
return children(dimensionsData);
87+
};
88+
89+
const setUpDimensionComponent = () => {
90+
const dimensions = {} as IDimensionsData;
91+
92+
render(
93+
<HookRenderer
94+
children={(dimensionsData: IDimensionsData) => {
95+
Object.assign(dimensions, dimensionsData);
96+
return null;
97+
}}
98+
/>
99+
);
100+
101+
return dimensions;
102+
};
103+
104+
describe("Testing Hooks", () => {
105+
it("responsiveHooks", () => {
106+
const data = setUpDimensionComponent();
107+
expect(data).toStrictEqual({
108+
window: { height: 20, width: 20, fontSize: 4.0794577223746264 },
109+
screen: { height: 20, width: 20, fontSize: 4.0794577223746264 }
110+
});
111+
});
112+
});

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"main": "src/index.js",
66
"scripts": {
77
"build": "tsc -p .",
8+
"start": "tsc -w",
89
"test": "jest"
910
},
1011
"files": [

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,5 @@
6767
/* Advanced Options */
6868
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
6969
},
70-
"exclude": ["node_modules", "RNMasonryExample", "lib"]
70+
"exclude": ["node_modules", "lib", "__mocks__", "__tests__"]
7171
}

0 commit comments

Comments
 (0)