Completed
Push — dev ( 6ada4c...6e0845 )
by Fike
31s
created

test/suite/acceptance/Stub/AppEvents.spec.js   A

Complexity

Total Complexity 21
Complexity/F 1.5

Size

Lines of Code 54
Function Count 14

Duplication

Duplicated Lines 54
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
c 1
b 0
f 0
nc 1
dl 54
loc 54
rs 10
wmc 21
mnd 0
bc 14
fnc 14
bpm 1
cpm 1.5
noi 0

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
/* eslint-env mocha */
2
3
var Chai = require('chai')
4
var expect = Chai.expect
5
6
var AppEvents = require('../../../../lib/Stub/AppEvents').AppEvents
7
8
describe('Acceptance', function () {
9
  describe('/Stub', function () {
10
    describe('/AppEvents.js', function () {
11
      describe('.AppEvents', function () {
12
        Object.keys(AppEvents).forEach(function (name) {
13
          describe('.' + name, function () {
14
            describe('< new', function () {
15
              var Event = AppEvents[name]
16
              it('creates ' + name + ' without any passed properties', function () {
17
                var lambda = function () {
18
                  return new Event()
19
                }
20
                expect(lambda).not.to.throw()
21
              })
22
23
              AppEvents[name]._properties.forEach(function (property) {
24
                it('provides default value for property `' + property + '`', function () {
25
                  expect(new Event()).to.have.property(property)
26
                })
27
28
                it('sets property `' + property + '`', function () {
29
                  var input = {}
30
                  var value = {x: 12}
31
                  input[property] = value
32
                  var event = new Event(input)
33
                  expect(event).to.have.property(property).eq(value)
34
                })
35
              })
36
37
              it('doesn\'t set `name` property', function () {
38
                var value = {x: 12}
39
                var event = new Event({name: value})
40
                expect(event.name).not.to.eq(value)
41
              })
42
43
              it('sets arbitrary property', function () {
44
                var value = {x: 12}
45
                var property = 'wharrgarbl'
46
                var input = {}
47
                input[property] = value
48
                expect(new Event(input)).to.have.property(property).eq(value)
49
              })
50
            })
51
          })
52
        })
53
      })
54
    })
55
  })
56
})
57