Completed
Push — master ( d5ffb5...8c40a0 )
by Ajeh
43s
created

main.spec.js ➔ describe(ꞌUtility #cloneObjꞌ)   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

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

2 Functions

Rating   Name   Duplication   Size   Complexity  
A main.spec.js ➔ ... ➔ it(ꞌThe solution: cloned object should not be equal to original after alteringꞌ) 0 6 1
A main.spec.js ➔ ... ➔ it(ꞌThe problem: Altering an object "objA" affects "objB"ꞌ) 0 6 1
1
/**
2
 * Created by Emmy on 10/7/2017.
3
 */
4
5
import * as Utility from '../../../../src/plugin/js/utilities'
6
import should from 'should'
7
8
describe('Utility #cloneObj', function () {
9
    it('The problem: Altering an object "objA" affects "objB"', function () {
10
        let objA = {foo: 'abc', bar: '123'};
11
        let objB = objA;
12
        objA.bar = '1234';
13
        should(objA).be.exactly(objB)
14
    })
15
16
    it('The solution: cloned object should not be equal to original after altering', function () {
17
        let objA = {foo: 'abc', bar: '123'};
18
        let objB = Utility.cloneObj(objA);
19
        objA.bar = '1234';
20
        should(objA).not.be.exactly(objB)
21
    })
22
})
23
24
describe('Utility #mergeObjs', function () {
25
    it('"objC" should be "objA" and "objB"', function () {
26
        let objA = {foo: 'abc'};
27
        let objB = {bar: '123'};
28
        let objC = Utility.mergeObjs(objA, objB);
29
30
        should(objC).have.keys('foo', 'bar')
31
    })
32
})
33
34
describe('Utility #firstIndex', function () {
35
    let arr = [{color: 'yellow'}, {color: 'red'}, {color: 'blue'}]
36
37
    it('First index of red should be 1', function () {
38
        should(Utility.firstIndex(arr, 'red', 'color')).be.exactly(1).and.a.Number()
39
    })
40
41
    it('First index of yellow should be 0', function () {
42
        should(Utility.firstIndex(arr, 'yellow', 'color')).be.exactly(0).and.a.Number()
43
    })
44
45
    it('First index of blue should be 0', function () {
46
        should(Utility.firstIndex(arr, 'blue', 'color')).be.exactly(2).and.a.Number()
47
    })
48
49
    it('First index of black should be undefined', function () {
50
        should(Utility.firstIndex(arr, 'black', 'color')).be.exactly(-1).and.a.Number()
51
    })
52
})