Completed
Push — master ( 40c2b4...09bd06 )
by Justin
01:29
created

utils.js ➔ ... ➔ describe(ꞌmergeꞌ)   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 59

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 59
rs 9.597

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
var assert = require('chai').assert,
2
    utils = require('../src/utils'),
3
    GedcomX = require('../');
4
5
describe('utils', function(){
6
  
7
  it('removeEmpty', function(){
8
    assert.deepEqual(
9
      utils.removeEmpty({
10
        a: undefined,
11
        b: 0,
12
        c: false,
13
        d: null,
14
        e: ''
15
      }),
16
      {
17
        b: 0,
18
        c: false,
19
        d: null,
20
        e: ''
21
      }
22
    );
23
  });
24
  
25
  it('pick', function(){
26
    assert.deepEqual(
27
      utils.pick({
28
        a: '1',
29
        b: 2,
30
        c: undefined,
31
        d: null
32
      }, ['a','c']),
33
      {
34
        a: '1',
35
        c: undefined
36
      }
37
    );
38
  });
39
  
40
  describe('merge', function(){
41
    
42
    it('objects', function(){
43
      var dest = {},
44
          merged = utils.merge(
45
            dest,
46
            {
47
              a: 1,
48
              b: {
49
                b1: 'foo'
50
              }
51
            },
52
            {
53
              a: 2,
54
              b: {
55
                b2: 'bar'
56
              }
57
            }
58
          );
59
      assert.strictEqual(dest, merged);
60
      assert.deepEqual(
61
        dest,
62
        {
63
          a: 2,
64
          b: {
65
            b1: 'foo',
66
            b2: 'bar'
67
          }
68
        }
69
      );
70
    });
71
    
72
    it('arrays', function(){
73
      var dest = {},
74
          merged = utils.merge(
75
            dest,
76
            {
77
              facts: [
78
                {
79
                  date: {
80
                    formal: '+2001'
81
                  }
82
                }  
83
              ]
84
            }
85
          );
86
      assert.strictEqual(dest, merged);
87
      assert.deepEqual(dest, {
88
        facts: [
89
          {
90
            date: {
91
              formal: '+2001'
92
            }
93
          }  
94
        ]
95
      });
96
    });
97
    
98
  });
99
  
100
  describe('toJSON', function(){
101
    
102
    it('arrays', function(){
103
      assert.deepEqual(
104
        utils.toJSON({
105
          facts: [
106
            GedcomX.Fact({
107
              date: {
108
                formal: '+2001'
109
              }
110
            })
111
          ]
112
        }),
113
        {
114
          facts: [
115
            {
116
              date: {
117
                formal: '+2001'
118
              }
119
            }  
120
          ]
121
        }
122
      );
123
    });
124
    
125
  });
126
  
127
});