generated from justsml/exercises-template
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
codegrade_mvp.test.js
107 lines (102 loc) · 3.22 KB
/
codegrade_mvp.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import functions from './index';
describe('fooFunction', ()=>{
it('foo returns foo', ()=>{
expect(functions.foo()).toBe('bar');
})
});
describe('Instances of Person', () => {
let neo
const foods = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
beforeEach(() => {
neo = new functions.Person('Neo', 20)
})
it('initialize with the given name', () => {
expect(neo.name).toBe('Neo')
})
it('initialize with the given age', () => {
expect(neo.age).toBe(20)
})
it('initialize with an empty stomach', () => {
expect(neo.stomach).toEqual([])
expect(neo.stomach.length).toBe(0)
})
it('get eat, poop and toString methods from their prototype', () => {
expect(neo.__proto__.eat).toBeDefined();
expect(neo.__proto__.poop).toBeDefined();
expect(neo.__proto__.toString).toBeDefined();
})
it('can eat up to 10 foods', () => {
foods.forEach(item => neo.eat(item))
foods.forEach(item => expect(neo.stomach).toContain(item))
})
it('can eat no more than 10 foods', () => {
foods.forEach(item => neo.eat(item))
neo.eat(11)
expect(neo.stomach).not.toBe(11)
})
it('can poop to empty stomach', () => {
foods.forEach(item => neo.eat(item))
neo.poop()
expect(neo.stomach.length).toEqual(0)
})
it('can state name and age', () => {
const str = neo.toString()
expect(str).toContain('Neo')
expect(str).toContain('20')
})
})
//car
describe('Instances of Car', () => {
let batmobile
beforeEach(() => {
batmobile = new functions.Car('BatMobile', 20)
})
it('initialize with the given model', () => {
expect(batmobile.model).toBe('BatMobile')
})
it('initialize with the given milesPerGallon', () => {
expect(batmobile.milesPerGallon).toEqual(20)
})
it('initialize with an empty tank', () => {
expect(batmobile.tank).toEqual(0)
})
it('initialize with an odometer at 0 miles', () => {
expect(batmobile.odometer).toEqual(0)
})
it('get fill methods from their prototype', () => {
expect(batmobile.__proto__.fill).not.toBeUndefined();
})
it('fill method increases the tank by the given gallons', () => {
batmobile.fill(10)
expect(batmobile.tank).toEqual(10)
batmobile.fill(10)
expect(batmobile.tank).toEqual(20)
})
})
describe('Instances of Baby', () => {
let baby
beforeEach(() => {
baby = new functions.Baby('Lucy', 5, 'trains')
})
it('initialize with the given name', () => {
expect(baby.name).toBe('Lucy')
})
it('initialize with the given age', () => {
expect(baby.age).toEqual(5)
})
it('initialize with the given favorite toy', () => {
expect(baby.favoriteToy).toBe('trains')
})
it('get a play method from their prototype', () => {
expect(baby.__proto__.play).not.toBeUndefined();
})
it('can play with favorite toy', () => {
expect(baby.play()).toContain('trains')
})
it('inherit the methods on Person.prototype', () => {
expect(baby.__proto__.eat).not.toBeUndefined();
})
it('inherit the methods on Person.prototype', () => {
expect(baby.__proto__.poop).not.toBeUndefined();
})
})