@@ -16,60 +16,69 @@ 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- describe ( "contains" , ( ) => {
20- test ( "returns true if the object contains the property" , ( ) => {
21- expect ( contains ( { a : 1 , b : 2 } , "a" ) ) . toBe ( true ) ;
22- expect ( contains ( { a : 1 , b : 2 } , "b" ) ) . toBe ( true ) ;
23-
24- } ) ;
25- test ( "returns false when the object does not contain the property" , ( ) => {
26- expect ( contains ( { a : 1 , b : 2 } , "c" ) ) . toBe ( false ) ;
27- expect ( contains ( { a : 1 , b : 2 } , "d" ) ) . toBe ( false ) ;
28- } ) ;
2919
3020// Given an empty object
3121// When passed to contains
3222// Then it should return false
33- test ( "returns false for an empty object" , ( ) => {
34- expect ( contains ( { } , "a" ) ) . toBe ( false ) ;
35- } ) ;
36- } ) ;
3723
24+ // Given an object with properties
25+ // When passed to contains with an existing property name
26+ // Then it should return true
3827
28+ // Given an object with properties
29+ // When passed to contains with a non-existent property name
30+ // Then it should return false
3931
40- describe ( "contains" , ( ) => {
41- test ( "returns false if the object is missing" , ( ) => {
42- expect ( contains ( { a : 1 , b :2 } ) ) . toBe ( false ) ;
43- } ) ;
32+ // Given invalid parameters like an array
33+ // When passed to contains
34+ // Then it should return false or throw an error
4435
45- test ( "returns false for an empty object" , ( ) => {
46- expect ( contains ( { } ) . toBe ( false ) ;
47- } ) ;
36+ // Given an empty object
37+ // When passed to contains
38+ // Then it should return false
39+ test ( "returns false for an empty object" , ( ) => {
40+ expect ( contains ( { } , "a" ) ) . toEqual ( false ) ;
4841} ) ;
4942
5043// Given an object with properties
5144// When passed to contains with an existing property name
5245// Then it should return true
53- test ( "returns true if the object contains the existing property name" , ( ) => {
54- expect ( contains ( { a : 1 , b : 2 } , "a" ) ) . toBe ( true ) ;
55- expect ( contains ( { a : 1 , b : 2 } , "b" ) ) . toBe ( true ) ;
56- expect ( contains ( { a : 1 , b : 2 } , "c" ) ) . toBe ( false ) ;
57- } ) ;
58-
46+ test ( "returns true when the property exists" , ( ) => {
47+ expect ( contains ( { a : 1 , b : 2 } , "a" ) ) . toEqual ( true ) ;
48+ expect ( contains ( { a : 1 , b : 2 } , "b" ) ) . toEqual ( true ) ;
49+ } ) ;
5950
6051// Given an object with properties
6152// When passed to contains with a non-existent property name
6253// Then it should return false
54+ test ( "returns false when the property does not exist" , ( ) => {
55+ expect ( contains ( { a : 1 , b : 2 } , "c" ) ) . toEqual ( false ) ;
56+ } ) ;
6357
64- test ( "returns false when given an invalid object" , ( ) => {
65- expect ( contains ( null , "a" ) ) . toBe ( false ) ;
66- expect ( contains ( undefined , "a" ) ) . toBe ( false ) ;
67- } ) ;
68-
69- // Given invalid parameters like an array
58+ // Given an object with several properties
59+ // When checking another existing property
60+ // Then it should return true
61+ test ( "returns true for another existing property" , ( ) => {
62+ expect ( contains ( { name : "Alice" , age : 25 } , "age" ) ) . toEqual ( true ) ;
63+ } ) ;
64+
65+ // Given an array
7066// When passed to contains
71- // Then it should return false or throw an error
72- test ( "returns false or throw an error when given an invalid object" , ( ) => {
73- expect ( contains ( null , "a" ) ) . toBe ( false ) ;
74- expect ( contains ( undefined , "a" ) ) . toBe ( false ) ;
75- } ) ;
67+ // Then it should return false
68+ test ( "returns false when given an array" , ( ) => {
69+ expect ( contains ( [ 1 , 2 , 3 ] , "0" ) ) . toEqual ( false ) ;
70+ } ) ;
71+
72+ // Given a null value
73+ // When passed to contains
74+ // Then it should return false
75+ test ( "returns false when given null" , ( ) => {
76+ expect ( contains ( null , "a" ) ) . toEqual ( false ) ;
77+ } ) ;
78+
79+ // Given an undefined value
80+ // When passed to contains
81+ // Then it should return false
82+ test ( "returns false when given undefined" , ( ) => {
83+ expect ( contains ( undefined , "a" ) ) . toEqual ( false ) ;
84+ } ) ;
0 commit comments