@@ -20,16 +20,38 @@ 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 ( "should return false when an empty object is passed to the function" , ( ) => {
24+ expect ( contains ( { } ) ) . toEqual ( false ) ;
25+ } ) ;
2426
2527// Given an object with properties
2628// When passed to contains with an existing property name
2729// Then it should return true
28-
30+ test ( "the function should return true when object contains a given property" , ( ) => {
31+ expect ( contains ( { a : 1 , b : 2 , c : 3 } , "c" ) ) . toEqual ( true ) ;
32+ expect ( contains ( { name : "lee" , age : 30 } , "name" ) ) . toEqual ( true ) ;
33+ expect ( contains ( { place : "spain" , city : "madrid" , rank : 9 } , "city" ) ) . toEqual (
34+ true
35+ ) ;
36+ expect ( contains ( { zone : 2 , zone : 3 , zone : 4 } , "zone" ) ) . toEqual ( true ) ;
37+ } ) ;
2938// Given an object with properties
3039// When passed to contains with a non-existent property name
3140// Then it should return false
41+ test ( "the function should return false when property don't exist in the given object" , ( ) => {
42+ expect ( contains ( { a : 1 , b : 2 , c : 3 } , "d" ) ) . toEqual ( false ) ;
43+ expect ( contains ( { year : 1998 , month : 10 , Date : 16 } , "age" ) ) . toEqual ( false ) ;
44+ expect (
45+ contains ( { meal : "pizza" , drink : "water" , table : 3 } , "starter" )
46+ ) . toEqual ( false ) ;
47+ } ) ;
3248
3349// Given invalid parameters like an array
3450// When passed to contains
3551// Then it should return false or throw an error
52+ test ( "the function should return false when invalid parameter like an array is passed" , ( ) => {
53+ expect ( contains ( [ 10 , 23 , 34 , 45 ] , "3" ) ) . toEqual ( false ) ;
54+ expect ( contains ( "hello" , "0" ) ) . toEqual ( false ) ;
55+ expect ( contains ( [ "green" , "yellow" , "rad" ] , "0" ) ) . toEqual ( false ) ;
56+ expect ( contains ( ( ( 30 , 40 , 50 ) , 30 ) ) ) . toEqual ( false ) ;
57+ } ) ;
0 commit comments