-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtest.js
39 lines (32 loc) · 917 Bytes
/
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
'use strict';
require('mocha');
var assert = require('assert');
var forIn = require('./');
describe('.forIn()', function() {
it('should loop through all properties in the object.', function() {
var obj = {a: 'foo', b: 'bar', c: 'baz'};
var values = [];
var keys = [];
forIn(obj, function(value, key, o) {
assert.deepEqual(o, obj);
keys.push(key);
values.push(value);
});
assert.deepEqual(keys, ['a', 'b', 'c']);
assert.deepEqual(values, ['foo', 'bar', 'baz']);
});
it('should break the loop early if `false` is returned.', function() {
var obj = {a: 'foo', b: 'bar', c: 'baz'};
var values = [];
var keys = [];
forIn(obj, function(value, key, o) {
if (key === 'b') {
return false;
}
keys.push(key);
values.push(value);
});
assert.deepEqual(keys, ['a']);
assert.deepEqual(values, ['foo']);
});
});