|
2 | 2 |
|
3 | 3 | const includes = require("./includes.js"); |
4 | 4 |
|
| 5 | +// Given an array containing the target value |
| 6 | +// When passed to the includes function |
| 7 | +// Then it should return true |
5 | 8 | test("returns true when target is in array", () => { |
6 | 9 | const currentOutput = includes(["a", "b", "c", "d"], "c"); |
7 | 10 | const targetOutput = true; |
8 | 11 |
|
9 | 12 | expect(currentOutput).toEqual(targetOutput); |
10 | 13 | }); |
11 | 14 |
|
| 15 | +// Given an array that does not contain the target value |
| 16 | +// When passed to the includes function |
| 17 | +// Then it should return false |
12 | 18 | test("returns false when target not in array", () => { |
13 | 19 | const currentOutput = includes([1, 2, 3, 4], "a"); |
14 | 20 | const targetOutput = false; |
15 | 21 |
|
16 | 22 | expect(currentOutput).toEqual(targetOutput); |
17 | 23 | }); |
18 | 24 |
|
| 25 | +// Given an array where the target appears more than once |
| 26 | +// When passed to the includes function |
| 27 | +// Then it should still return true |
19 | 28 | test("returns true when the target is in array multiple times", () => { |
20 | 29 | const currentOutput = includes([1, 2, 2, 3], 2); |
21 | 30 | const targetOutput = true; |
22 | 31 |
|
23 | 32 | expect(currentOutput).toEqual(targetOutput); |
24 | 33 | }); |
25 | 34 |
|
| 35 | +// Given an empty array |
| 36 | +// When passed to the includes function |
| 37 | +// Then it should return false |
26 | 38 | test("returns false for empty array", () => { |
27 | 39 | const currentOutput = includes([]); |
28 | 40 | const targetOutput = false; |
29 | 41 |
|
30 | 42 | expect(currentOutput).toEqual(targetOutput); |
31 | 43 | }); |
32 | 44 |
|
| 45 | +// Given an array containing null as an element |
| 46 | +// When passed to the includes function with null as the target |
| 47 | +// Then it should return true |
33 | 48 | test("searches for null", () => { |
34 | 49 | const currentOutput = includes(["b", "z", null, "a"], null); |
35 | 50 | const targetOutput = true; |
|
0 commit comments