1- const contains = require ( "./contains.js" ) ;
1+ const contains = require ( "./contains" )
22
33/*
44Implement a function called contains that checks an object contains a
@@ -16,20 +16,44 @@ 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 ( "contains returns true for existing property" , ( ) => {
20+ const currentOutput = contains ( { a :1 , b :2 } , 'a' ) ;
21+ const targetOutput = true ;
22+ expect ( currentOutput ) . toEqual ( targetOutput ) ;
23+ } ) ;
1924
2025// Given an empty object
2126// When passed to contains
2227// Then it should return false
23- test . todo ( "contains on empty object returns false" ) ;
28+ test ( "contains on empty object returns false" , ( ) => {
29+ const currentOutput = contains ( { } , 'a' ) ;
30+ const targetOutput = false ;
31+ expect ( currentOutput ) . toEqual ( targetOutput ) ;
32+ } ) ;
2433
2534// Given an object with properties
2635// When passed to contains with an existing property name
2736// Then it should return true
37+ test ( "contains returns true for existing property" , ( ) => {
38+ const currentOutput = contains ( { a :1 , b :2 } , 'b' ) ;
39+ const targetOutput = true ;
40+ expect ( currentOutput ) . toEqual ( targetOutput ) ;
41+ } ) ;
2842
2943// Given an object with properties
3044// When passed to contains with a non-existent property name
3145// Then it should return false
46+ test ( "contains returns false for non-existent property" , ( ) => {
47+ const currentOutput = contains ( { a :1 , b :2 } , 'c' ) ;
48+ const targetOutput = false ;
49+ expect ( currentOutput ) . toEqual ( targetOutput ) ;
50+ } ) ;
3251
3352// Given invalid parameters like an array
3453// When passed to contains
3554// Then it should return false or throw an error
55+ test ( "contains returns false for invalid parameters" , ( ) => {
56+ const currentOutput = contains ( [ 1 , 2 , 3 ] , 'a' ) ;
57+ const targetOutput = false ;
58+ expect ( currentOutput ) . toEqual ( targetOutput ) ;
59+ } ) ;
0 commit comments