@@ -20,16 +20,32 @@ as the object doesn't contains a key of 'c'
2020// Given an empty object
2121// When passed to contains
2222// Then it should return false
23- test . todo ( "contains on empty object returns false" ) ;
23+ test ( "contains on empty object returns false" , ( ) =>
24+ expect ( contains ( { } , "key1" ) ) . toEqual ( false ) ) ;
2425
2526// Given an object with properties
2627// When passed to contains with an existing property name
2728// Then it should return true
29+ test ( "contains returns true when object contains the given property" , ( ) =>
30+ expect ( contains ( { key1 : "value1" , key2 : "value2" } , "key1" ) ) . toEqual ( true ) ) ;
2831
2932// Given an object with properties
3033// When passed to contains with a non-existent property name
3134// Then it should return false
35+ test ( "contains returns false when object does not contain the given property" , ( ) =>
36+ expect ( contains ( { key1 : "value1" , key2 : "value2" } , "key4" ) ) . toEqual ( false ) ) ;
3237
3338// Given invalid parameters like an array
3439// When passed to contains
3540// Then it should return false or throw an error
41+ it ( "contains returns false or throws an error if given parameter is not a valid object" , ( ) => {
42+ expect ( contains ( [ ] , "key1" ) ) . toEqual ( false ) ;
43+ expect ( contains ( "key1:value1" , "key1" ) ) . toEqual ( false ) ;
44+ expect ( contains ( 5235 , "key1" ) ) . toEqual ( false ) ;
45+ expect ( ( ) => contains ( undefined , "key1" ) ) . toThrow (
46+ "The parameter given is not a plain JS object."
47+ ) ;
48+ expect ( ( ) => contains ( null , "key1" ) ) . toThrow (
49+ "The parameter given is not a plain JS object."
50+ ) ;
51+ } ) ;
0 commit comments