UNPKG

1.02 kBJavaScriptView Raw
1/*!
2 * for-in <https://github.com/jonschlinkert/for-in>
3 *
4 * Copyright (c) 2014 Jon Schlinkert, contributors.
5 * Licensed under the MIT License
6 */
7
8'use strict';
9
10var should = require('should');
11var forIn = require('./');
12
13describe('.forIn()', function () {
14 it('should loop through all properties in the object.', function () {
15 var obj = {a: 'foo', b: 'bar', c: 'baz'};
16 var values = [];
17 var keys = [];
18
19 forIn(obj, function (value, key, o) {
20 o.should.eql(obj);
21 keys.push(key);
22 values.push(value);
23 });
24
25 keys.should.eql(['a', 'b', 'c']);
26 values.should.eql(['foo', 'bar', 'baz']);
27 });
28
29 it('should break the loop early if `false` is returned.', function () {
30 var obj = {a: 'foo', b: 'bar', c: 'baz'};
31 var values = [];
32 var keys = [];
33
34 forIn(obj, function (value, key, o) {
35 if (key === 'b') {
36 return false;
37 }
38 keys.push(key);
39 values.push(value);
40 });
41
42 keys.should.eql(['a']);
43 values.should.eql(['foo']);
44 });
45});