-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilter.test.js
41 lines (33 loc) · 1.09 KB
/
filter.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const filter = require("./filter");
describe("Filter function", () => {
test("it should filter by a search term (link)", () => {
const input = [
{ id: 1, url: "https://www.url1.dev" },
{ id: 2, url: "https://www.url2.dev" },
{ id: 3, url: "https://www.link3.dev" }
];
const output = [{ id: 3, url: "https://www.link3.dev" }];
expect(filter(input, "link")).toEqual(output);
expect(filter(input, "LINK")).toEqual(output);
});
test("it should filter by a search term (uRl)", () => {
// solution ex 1
const input = [
{ id: 1, url: "https://www.url1.dev" },
{ id: 2, url: "https://www.url2.dev" },
{ id: 3, url: "https://www.link3.dev" }
];
const output = [
{ id: 1, url: "https://www.url1.dev" },
{ id: 2, url: "https://www.url2.dev" }
];
expect(filter(input, "uRl")).toEqual(output);
});
test("it should throw when searchTerm is empty string", () => {
// solution ex 2
const input = [];
expect(() => {
filter(input, "");
}).toThrowError(Error("searchTerm cannot be empty"));
});
});