-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
assumptions.test.js
66 lines (55 loc) · 1.26 KB
/
assumptions.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
/**
* /*
* This file contains tests for various assumptions that we made while implementing the code.
* If these tests start to fail, then we will have bugs.
*
* @format
*/
const _ = require("lodash");
describe("lodash", () => {
describe("castArray", () => {
// In arrayify, we once assumed that iterables were turned into arrays by _.castArray
it("DOES NOT turn iterables into arrays", () => {
const rangeIterable = {
from: 1,
to: 5,
[Symbol.iterator]() {
this.current = this.from;
return this;
},
next() {
const { current, to } = this;
this.current++;
return {
value: current,
done: current > to,
};
},
};
expect([...rangeIterable]).toHaveLength(5);
expect(_.castArray(rangeIterable)).toHaveLength(1);
});
});
describe("toArray", () => {
it("does turn iterables into arrays", () => {
const rangeIterable = {
from: 1,
to: 5,
[Symbol.iterator]() {
this.current = this.from;
return this;
},
next() {
const { current, to } = this;
this.current++;
return {
value: current,
done: current > to,
};
},
};
expect([...rangeIterable]).toHaveLength(5);
expect(_.toArray(rangeIterable)).toHaveLength(5);
});
});
});