@@ -16,20 +16,47 @@ as the object doesn't contains a key of 'c'
1616// Given a contains function
1717// When passed an object and a property name
1818// Then it should return true if the object contains the property, false otherwise
19+ test ( "returns true when object contains the property" , ( ) => {
20+ const obj = { a : 1 , b : 2 } ;
21+ expect ( contains ( obj , "a" ) ) . toBe ( true ) ;
22+ } ) ;
23+
24+ test ( "returns false when object does not contain the property" , ( ) => {
25+ const obj = { a : 1 , b : 2 } ;
26+ expect ( contains ( obj , "c" ) ) . toBe ( false ) ;
27+ } ) ;
28+
1929
2030// Given an empty object
2131// When passed to contains
2232// Then it should return false
23- test . todo ( "contains on empty object returns false" ) ;
33+ // test.todo("contains on empty object returns false");
34+ test ( "contains on empty object returns false" , ( ) => {
35+ expect ( contains ( { } , "a" ) ) . toBe ( false ) ;
36+ } ) ;
2437
2538// Given an object with properties
2639// When passed to contains with an existing property name
2740// Then it should return true
41+ test ( "returns true when object contains the property" , ( ) => {
42+ const obj = { a : 1 , b : 2 } ;
43+ expect ( contains ( obj , "a" ) ) . toBe ( true ) ;
44+ } ) ;
2845
2946// Given an object with properties
3047// When passed to contains with a non-existent property name
3148// Then it should return false
49+ test ( "returns false when object does not contain the property" , ( ) => {
50+ const obj = { a : 1 , b : 2 } ;
51+ expect ( contains ( obj , "c" ) ) . toBe ( false ) ;
52+ } ) ;
3253
3354// Given invalid parameters like an array
3455// When passed to contains
3556// Then it should return false or throw an error
57+ test ( "returns false for invalid parameters like an array" , ( ) => {
58+ expect ( contains ( [ ] , "a" ) ) . toBe ( false ) ;
59+ expect ( contains ( null , "a" ) ) . toBe ( false ) ;
60+ expect ( contains ( 123 , "a" ) ) . toBe ( false ) ;
61+ expect ( contains ( "hello" , "a" ) ) . toBe ( false ) ;
62+ } ) ;
0 commit comments