-
Notifications
You must be signed in to change notification settings - Fork 4
/
pickerSpec.js
43 lines (38 loc) · 1.32 KB
/
pickerSpec.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
(function (Random) {
describe("picker", function () {
it("returns a function that allows for indexing upon the provided array", function () {
var engine = function () {};
var length = 1337;
var index = 1234;
var spy = jasmine.createSpy().andReturn(index);
spyOn(Random, "integer").andReturn(spy);
var array = {
length: length
};
var dummy = "hello";
array[index] = dummy;
var picker = Random.picker(array);
var actual = picker(engine);
expect(Random.integer).toHaveBeenCalledWith(0, length - 1);
expect(spy).toHaveBeenCalledWith(engine);
expect(actual).toBe(dummy);
});
it("clones the initial array rather than holding onto the reference", function () {
var engine = function () {};
var length = 1337;
var index = 1234;
var spy = jasmine.createSpy().andReturn(index);
spyOn(Random, "integer").andReturn(spy);
var array = {
length: length
};
var dummy = "hello";
array[index] = dummy;
var picker = Random.picker(array);
array[index] = "there";
array.length = 0;
var actual = picker(engine);
expect(actual).toBe(dummy);
});
});
}(typeof module !== "undefined" ? require("../lib/random") : Random));