-
Notifications
You must be signed in to change notification settings - Fork 0
/
each.test.js
34 lines (25 loc) · 885 Bytes
/
each.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
const { each } = require("../src/datamix");
const sinon = require("sinon");
describe("each", () => {
it("behaves like Array.forEach on arrays", function () {
let callback = sinon.fake();
let array = ["a", "b"];
each(array, callback);
expect(callback.calledWith("a", 0, array)).toBe(true);
expect(callback.calledWith("b", 1, array)).toBe(true);
});
it("behaves like Array.forEach on objects", function () {
let callback = sinon.fake();
let object = {a: 1, b: 2};
each(object, callback);
expect(callback.calledWith(1, "a", object)).toBe(true);
expect(callback.calledWith(2, "b", object)).toBe(true);
});
it("ignores nil data", function () {
let callback = sinon.fake();
let object = {a: 1, b: 2};
each(null, callback);
each(undefined, callback);
expect(callback.called).toBe(false);
});
});