Skip to content

Commit 30e1273

Browse files
BLANC Etienne DISU/UOMBLANC Etienne DISU/UOM
authored andcommitted
bug with test length checks
1 parent 4e8210f commit 30e1273

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { ToyMachine, SantaSleigh, Present } from "./christmasDelivery";
2+
3+
const toyMachine = new ToyMachine();
4+
const santaSleigh = new SantaSleigh();
5+
6+
describe("ToyMachine object...", () => {
7+
describe("makePresent() method:", () => {
8+
// Reinit present stock:
9+
toyMachine.presentStock = [];
10+
// Make present in stock:
11+
toyMachine.makePresent();
12+
// Check:
13+
test("should presentStock have a length of 1 after make", () => {
14+
expect(toyMachine.presentStock).toHaveLength(1);
15+
});
16+
describe("givePresent() method:", () => {
17+
toyMachine.makePresent();
18+
const stockBefore = toyMachine.presentStock.length;
19+
// Do method:
20+
toyMachine.givePresent();
21+
// Check:
22+
test("should presentStock have a length of 1 after make", () => {
23+
expect(toyMachine.presentStock).toHaveLength(stockBefore - 1);
24+
});
25+
});
26+
});
27+
});
28+
29+
describe("SantaSleigh object...", () => {
30+
describe("putPresentOnBoard() method:", () => {
31+
test("should output a Present object", () => {
32+
// Reinit presents on sleigh:
33+
santaSleigh.presents = [];
34+
// Put a present on board:
35+
santaSleigh.putPresentOnBoard(new Present());
36+
// Check:
37+
expect(santaSleigh.presents).toHaveLength(1);
38+
});
39+
});
40+
});
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
export class Present {}
2+
3+
export class ToyMachine {
4+
presentStock: Array<Present> = [];
5+
makePresent = () => {
6+
this.presentStock.push(new Present());
7+
};
8+
givePresent = () => {
9+
const presentToDeliver = this.presentStock.slice(0, 1);
10+
return presentToDeliver;
11+
};
12+
}
13+
14+
export class Elf {}
15+
16+
export class SantaSleigh {
17+
presents: Array<Present> = [];
18+
putPresentOnBoard = (present: Present) => {
19+
this.presents.push(present);
20+
};
21+
}
22+
123
// == MAIN ==
224
if (require.main === module) {
325
}

0 commit comments

Comments
 (0)