@@ -76,34 +76,61 @@ describe("- getDataFromSpecificAddress helper (Unit Test)", () => {
7676 } ) ;
7777 } ) ;
7878
79- // describe("2) Check cases return cases .", () => {
80- // msg =
81- // "Should return a object type with data attribute if a valid ip is passed (This function expects a single argument of string type)";
82- // it(msg, async () => {
83- // getDataFromSpecificAddressResult = await getDataFromSpecificAddress(
84- // MOCK_VALID_IP_VALUE
85- // );
86- // // await expect(typeof getDataFromSpecificAddressResult == "string").toBe(
87- // // true
88- // // );
89- // } );
90- // });
79+ describe ( "2) Check cases for error ." , ( ) => {
80+ msg =
81+ "Should not thrown an Error if a new Error is passed for arguments. (This function expects a single argument of string type)" ;
82+ it ( msg , async ( ) => {
83+ let newError = new Error ( ) ;
84+ getDataFromSpecificAddressResult = await getDataFromSpecificAddress (
85+ newError
86+ ) ;
87+ await expect ( async ( ) => getDataFromSpecificAddressResult ) . not . toThrow (
88+ Error
89+ ) ;
90+ } ) ;
9191
92- // describe("2) Check cases for error.", () => {
93- // msg =
94- // "Should not return a error message and not throw an error if no argument is passed to the function.";
95- // it(msg, async () => {
96- // await expect(async () => await getDataFromSpecificAddress()).not.toThrow(
97- // Error
98- // );
99- // });
92+ msg =
93+ "Should not thrown an Error if no arguments is passed to the function. (This function expects a single argument of string type)" ;
94+ it ( msg , async ( ) => {
95+ getDataFromSpecificAddressResult = await getDataFromSpecificAddress ( ) ;
96+ await expect ( async ( ) => getDataFromSpecificAddressResult ) . not . toThrow (
97+ Error
98+ ) ;
99+ } ) ;
100+
101+ msg =
102+ "Should not thrown an Error if null value is passed to the function. (This function expects a single argument of string type)" ;
103+ it ( msg , async ( ) => {
104+ getDataFromSpecificAddressResult = await getDataFromSpecificAddress ( null ) ;
105+ await expect ( async ( ) => getDataFromSpecificAddressResult ) . not . toThrow (
106+ Error
107+ ) ;
108+ } ) ;
100109
101- // msg =
102- // "Should not return a error message and not throw an error if a new Error() is passed to the function.";
103- // it(msg, async () => {
104- // await expect(
105- // async () => await getDataFromSpecificAddress(new Error())
106- // ).not.toThrow(Error);
107- // });
108- // });
110+ msg =
111+ "Should not thrown an Error if undefined value is passed to the function. (This function expects a single argument of string type)" ;
112+ it ( msg , async ( ) => {
113+ getDataFromSpecificAddressResult = await getDataFromSpecificAddress (
114+ undefined
115+ ) ;
116+ await expect ( async ( ) => getDataFromSpecificAddressResult ) . not . toThrow (
117+ Error
118+ ) ;
119+ } ) ;
120+
121+ msg =
122+ "Should return a string type with 'ERROR in getDataFromSpecificAddress helper function.' value if a new Error is passed for arguments." ;
123+ it ( msg , async ( ) => {
124+ let newError = new Error ( ) ;
125+ const GET_DATA_FROM_SPECIFIC_ADDRESS_ERROR_NAME =
126+ "ERROR in getDataFromSpecificAddress helper function." ;
127+
128+ getDataFromSpecificAddressResult = await getDataFromSpecificAddress (
129+ newError
130+ ) ;
131+ await expect ( getDataFromSpecificAddressResult ) . toMatch (
132+ GET_DATA_FROM_SPECIFIC_ADDRESS_ERROR_NAME
133+ ) ;
134+ } ) ;
135+ } ) ;
109136} ) ;
0 commit comments