@@ -17,19 +17,47 @@ as the object doesn't contains a key of 'c'
1717// When passed an object and a property name
1818// Then it should return true if the object contains the property, false otherwise
1919
20+ test ( "returns true if the object contains the property" , ( ) => {
21+ const object = { a : 1 , b : 2 } ;
22+
23+ expect ( contains ( object , "a" ) ) . toBe ( true ) ;
24+ } ) ;
25+
26+ test ( "returns false if the object does not contain the property" , ( ) => {
27+ const object = { a : 1 , b : 2 } ;
28+
29+ expect ( contains ( object , "c" ) ) . toBe ( false ) ;
30+ } ) ;
31+
2032// Given an empty object
2133// When passed to contains
2234// Then it should return false
23- test . todo ( "contains on empty object returns false" ) ;
35+
36+ test ( "contains on empty object returns false" , ( ) => {
37+ expect ( contains ( { } , "a" ) ) . toBe ( false ) ;
38+ } ) ;
2439
2540// Given an object with properties
2641// When passed to contains with an existing property name
2742// Then it should return true
2843
44+ test ( "returns true when property exists" , ( ) => {
45+ expect ( contains ( { a : 1 , b : 2 } , "a" ) ) . toBe ( true ) ;
46+ } ) ;
47+
2948// Given an object with properties
3049// When passed to contains with a non-existent property name
3150// Then it should return false
3251
52+ test ( "returns false when property does not exist" , ( ) => {
53+ expect ( contains ( { a : 1 , b : 2 } , "c" ) ) . toBe ( false ) ;
54+ } ) ;
55+
56+
3357// Given invalid parameters like an array
3458// When passed to contains
3559// Then it should return false or throw an error
60+
61+ test ( "returns false for an array" , ( ) => {
62+ expect ( contains ( [ "a" , "b" ] , "0" ) ) . toBe ( false ) ;
63+ } ) ;
0 commit comments