UNPKG

592 BJavaScriptView Raw
1var test = require("tap").test
2 , forEach = require("..")
3
4test("forEach calls each iterator", function (t) {
5 var count = 0
6 t.plan(4)
7 forEach({ a: 1, b: 2 }, function (value, key) {
8 if (count === 0) {
9 t.equal(value, 1)
10 t.equal(key, "a")
11 } else {
12 t.equal(value, 2)
13 t.equal(key, "b")
14 }
15 count++
16 })
17})
18
19test("forEach calls iterator with correct this value", function (t) {
20 var thisValue = {}
21
22 t.plan(1)
23
24 forEach([0], function () {
25 t.equal(this, thisValue)
26 }, thisValue)
27})