Skip to content

Commit ebe456e

Browse files
committed
Refactor contains tests for clarity and consistency
1 parent 5dccf8a commit ebe456e

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

Sprint-2/implement/contains.test.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ test("contains returns true for existing property", () => {
2020
expect(contains({a: 1, b: 2}, 'a')).toBe(true);
2121
});
2222

23-
test("contains returns false for non-existent property", () => {
24-
expect(contains({a: 1, b: 2}, 'c')).toBe(false);
25-
});
23+
2624
// Given an empty object
2725
// When passed to contains
2826
// Then it should return false
@@ -33,7 +31,7 @@ test("contains returns false for empty object", () => {
3331
// Given an object with properties
3432
// When passed to contains with an existing property name
3533
// Then it should return true
36-
test("contains returns true for existing property", () => {
34+
test("returns true when property exists in object", () => {
3735
expect(contains({a: 1, b: 2}, 'a')).toBe(true);
3836
});
3937
// Given an object with properties
@@ -45,6 +43,18 @@ test("contains returns false for non-existent property", () => {
4543
// Given invalid parameters like an array
4644
// When passed to contains
4745
// Then it should return false or throw an error
48-
test("contains with invalid parameters returns false or throws error", () => {
49-
expect(contains([1, 2, 3], 'a')).toBe(false);
46+
test("contains with invalid input returns false", () => {
47+
expect(contains([], 'a')).toBe(false);
48+
expect(contains(123, 'a')).toBe(false);
49+
expect(contains("string", 'a')).toBe(false);
5050
});
51+
52+
test("returns false for null input", () => {
53+
expect(contains(null, 'a')).toBe(false);
54+
});
55+
56+
test("returns false for undefined input", () => {
57+
expect(contains(undefined, 'a')).toBe(false);
58+
});
59+
60+

0 commit comments

Comments
 (0)