Skip to content

Commit 1e8e343

Browse files
committed
Add tests for usePhone initiation and updates
1 parent 789a714 commit 1e8e343

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

tests/hooks.test.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {useCallback, useEffect, useRef, useState} from "react";
2+
import {act, renderHook} from "@testing-library/react";
23

34
import {displayFormat, getRawValue, parsePhoneNumber, usePhone} from "../src";
45

@@ -65,4 +66,19 @@ const usePhoneTester = ({
6566
}
6667

6768
describe("Verifying the functionality of hooks", () => {
69+
it("Check the usePhone hook initiation and updates", () => {
70+
const {result} = renderHook(usePhoneTester, {
71+
initialProps: {
72+
initialValue: "37411111111",
73+
}
74+
});
75+
expect(result.current.value).toBe("+374 (11) 111 111");
76+
expect((result.current.metadata as any)[0]).toBe("am");
77+
78+
act(() => result.current.update("1"));
79+
act(() => result.current.update("1111"));
80+
81+
expect(result.current.value).toBe("+1 (111)");
82+
expect((result.current.metadata as any)[0]).toBe("us");
83+
})
6884
})

0 commit comments

Comments
 (0)