@@ -11,25 +11,37 @@ E.g. contains({a: 1, b: 2}, 'c') // returns false
1111as the object doesn't contains a key of 'c'
1212*/
1313
14- // Acceptance criteria:
15-
1614// Given a contains function
1715// When passed an object and a property name
1816// Then it should return true if the object contains the property, false otherwise
17+ test ( "return true if object's property exists otherwise false" , ( ) => {
18+ expect ( contains ( { name : "maryam" , city : "Derby" } , "city" ) ) . toBe ( true ) ;
19+ } ) ;
1920
2021// Given an empty object
2122// When passed to contains
2223// Then it should return false
23- test . todo ( "contains on empty object returns false" ) ;
24+ test ( "return false if object is empty" , ( ) => {
25+ expect ( contains ( { } , "a" ) ) . toBe ( false ) ;
26+ } ) ;
2427
2528// Given an object with properties
2629// When passed to contains with an existing property name
2730// Then it should return true
31+ test ( "return true if object's property contains the property" , ( ) => {
32+ expect ( contains ( { name : "maryam" , city : "Derby" } , "city" ) ) . toBe ( true ) ;
33+ } ) ;
2834
2935// Given an object with properties
3036// When passed to contains with a non-existent property name
3137// Then it should return false
38+ test ( "return false if property is non-existent" , ( ) => {
39+ expect ( contains ( { name : "maryam" , city : "Derby" } , "age" ) ) . toBe ( false ) ;
40+ } ) ;
3241
3342// Given invalid parameters like an array
3443// When passed to contains
3544// Then it should return false or throw an error
45+ test ( "return false if it's not an object" , ( ) => {
46+ expect ( contains ( [ ] , 6 ) ) . toBe ( false ) ;
47+ } ) ;
0 commit comments