-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
javascript-2-b.spec.js
63 lines (52 loc) · 1.45 KB
/
javascript-2-b.spec.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// @ts-check
import { extract } from "./javascript-2-b";
const TEAM = {
name: "Buzzer Beaters",
coach: {
name: "Nancy",
achievements: {
titles: 2,
hallOfFame: true
}
},
location: {
town: "Miami",
state: "Florida"
},
players: [
{ name: "Candace", position: "Point guard" },
{ name: "Dawn", position: "Center" }
]
};
describe("extract", () => {
test(`property: name`, () => {
expect(extract(TEAM, "name")).toEqual("Buzzer Beaters");
});
test(`property: coach -> name`, () => {
expect(extract(TEAM, "coach.name")).toEqual("Nancy");
});
test(`property: coach -> achievement -> titles`, () => {
expect(extract(TEAM, "coach.achievements.titles")).toEqual(2);
});
test(`property: coach -> achievement -> hallOfFame`, () => {
expect(extract(TEAM, "coach.achievements.hallOfFame")).toEqual(true);
});
test(`property: location`, () => {
expect(extract(TEAM, "location")).toEqual({
town: "Miami",
state: "Florida"
});
});
test(`property: unknown`, () => {
expect(extract(TEAM, "unknown")).toEqual(null);
});
test(`property: players[0] -> name`, () => {
expect(extract(TEAM, "players[0].name")).toEqual("Candace");
});
test(`property: players[1] -> position`, () => {
expect(extract(TEAM, "players[1].position")).toEqual("Center");
});
test(`property: players[4] -> name`, () => {
expect(extract(TEAM, "players[4].name")).toEqual(null);
});
});