Completed
Push — master ( 2c40ae...326927 )
by Fike
38s
created

test/suite/unit/Utility/Objects.spec.js   A

Complexity

Total Complexity 9
Complexity/F 1

Size

Lines of Code 33
Function Count 9

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
c 1
b 0
f 0
nc 1
dl 0
loc 33
rs 10
wmc 9
mnd 0
bc 9
fnc 9
bpm 1
cpm 1
noi 0
1
/* eslint-env mocha */
2
/* global allure */
3
4
var Chai = require('chai')
5
var expect = Chai.expect
6
7
var Objects = require('../../../../lib/Utility/Objects').Objects
8
9
describe('Unit', function () {
10
  describe('/Utility', function () {
11
    describe('/Objects.js', function () {
12
      describe('.Objects', function () {
13
        describe('.copy', function () {
14
          var variants = [1, 1.0, true, false, null, undefined, 'string']
15
          variants.forEach(function (value) {
16
            it('passes through primitive value', function () {
17
              allure.addArgument('input', value)
18
              expect(Objects.copy(value)).to.equal(value)
19
            })
20
          })
21
22
          it('copies array contents', function () {
23
            var value = [1, 2, 3]
24
            var copy = Objects.copy(value)
25
            expect(copy).not.to.equal(value)
26
            expect(copy).to.deep.eq(value)
27
          })
28
        })
29
30
        describe('.merge', function () {
31
          var variantSetA = {
32
            number: 1.0,
33
            boolean: true,
34
            function: function () {}
35
          }
36
          Object.keys(variantSetA).forEach(function (key) {
37
            it('returns b if b is a ' + key, function () {
38
              var value = variantSetA[key]
39
              expect(Objects.merge({}, value)).to.eq(value)
40
            })
41
42
            it('returns b if a is a ' + key, function () {
43
              var value = variantSetA[key]
44
              var b = {}
45
              expect(Objects.merge(value, b)).to.eq(b)
46
            })
47
          })
48
49
          var variantSetB = {
50
            null: null,
51
            undefined: undefined
52
          }
53
54
          Object.keys(variantSetB).forEach(function (key) {
55
            it('returns a if b is a ' + key, function () {
56
              var a = {}
57
              expect(Objects.merge(a, variantSetB[key])).to.eq(a)
58
            })
59
60
            it('returns b if a is a ' + key, function () {
61
              var b = {}
62
              expect(Objects.merge(variantSetB[key], b)).to.eq(b)
63
            })
64
          })
65
66
          it('returns b if a is array', function () {
67
            var b = {}
68
            expect(Objects.merge([], b)).to.eq(b)
69
          })
70
71
          it('returns b if b is array', function () {
72
            var b = []
73
            expect(Objects.merge({}, b)).to.eq(b)
74
          })
75
76
          it('writes disjoint keys', function () {
77
            var a = {x: 12}
78
            var b = {y: 13}
79
            var expectation = {x: 12, y: 13}
80
            expect(Objects.merge(a, b)).to.deep.eq(expectation)
81
          })
82
83
          it('overwrites intersecting key', function () {
84
            var a = {x: 12}
85
            var b = {x: 13}
86
            expect(Objects.merge(a, b)).to.deep.eq(b)
87
          })
88
89
          it('overwrites intersecting keys recursively', function () {
90
            var a = {x: {y: 12}}
91
            var b = {x: {z: 13}}
92
            var expectation = {x: {y: 12, z: 13}}
93
            expect(Objects.merge(a, b)).to.deep.eq(expectation)
94
          })
95
        })
96
      })
97
    })
98
  })
99
})
100