Completed
Push — dev ( 249398...dac991 )
by Fike
39s
created

test/suites/unit/Schema/Validator.state.spec.js   B

Complexity

Total Complexity 40
Complexity/F 2.11

Size

Lines of Code 61
Function Count 19

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
wmc 40
nc 1
mnd 0
bc 19
fnc 19
dl 0
loc 61
rs 8.2608
bpm 1
cpm 2.1052
noi 7
c 1
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A Validator.state.spec.js ➔ describe(ꞌUnitꞌ) 0 56 1

How to fix   Complexity   

Complexity

Complex classes like test/suites/unit/Schema/Validator.state.spec.js often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
/* eslint-env mocha */
2
/* eslint-disable no-unused-expressions */
3
4
var Chai = require('chai')
5
var expect = Chai.expect
6
7
var Validator = require('../../../../lib/Schema/Validator').Validator
8
9
describe('Unit', function () {
10
  describe('/Schema', function () {
11
    describe('/Validator.js', function () {
12
      describe('.Validator', function () {
13
        describe('.state()', function () {
14
          it('reports fatal violation if falsey value is passed', function () {
15
            var result = Validator.state(null)
16
            expect(result.severity).to.eq(Validator.Severity.Fatal)
17
            expect(result.violations).to.have.property('$').not.empty
0 ignored issues
show
introduced by
The result of the property access to expect(result.violations...property("$").not.empty is not used.
Loading history...
18
          })
19
20
          it('reports fatal violation if transition handler is missing', function () {
21
            var input = {abort: function () {}}
22
            var result = Validator.state(input)
23
            expect(result.severity).to.eq(Validator.Severity.Fatal)
24
            expect(result.violations).to.have.property('$.transition').not.empty
0 ignored issues
show
introduced by
The result of the property access to expect(result.violations....transition").not.empty is not used.
Loading history...
25
          })
26
27
          it('reports fatal violation if transition handler is nor valid', function () {
28
            var input = {transition: true, abort: function () {}}
29
            var result = Validator.state(input)
30
            expect(result.severity).to.eq(Validator.Severity.Fatal)
31
            expect(result.violations).to.have.property('$.transition').not.empty
0 ignored issues
show
introduced by
The result of the property access to expect(result.violations....transition").not.empty is not used.
Loading history...
32
          })
33
34
          it('reports minor violation if abort handler is missing', function () {
35
            var input = {transition: function () {}}
36
            var result = Validator.state(input)
37
            expect(result.severity).to.eq(Validator.Severity.Minor)
38
            expect(result.violations).to.have.property('$.abort').not.empty
0 ignored issues
show
introduced by
The result of the property access to expect(result.violations...ty("$.abort").not.empty is not used.
Loading history...
39
          })
40
41
          it('reports fatal violation if abort handler is not valid', function () {
42
            var input = {transition: function () {}, abort: true}
43
            var result = Validator.state(input)
44
            expect(result.severity).to.eq(Validator.Severity.Fatal)
45
            expect(result.violations).to.have.property('$.abort').not.empty
0 ignored issues
show
introduced by
The result of the property access to expect(result.violations...ty("$.abort").not.empty is not used.
Loading history...
46
          })
47
48
          it('reports no violations if handlers are correct', function () {
49
            var input = {
50
              transition: function () {},
51
              abort: function () {}
52
            }
53
            expect(Validator.state(input).violations).to.be.empty
0 ignored issues
show
introduced by
The result of the property access to expect(Validator.state(i...violations).to.be.empty is not used.
Loading history...
54
          })
55
56
          it('doesn\'t report violation if function is passed', function () {
57
            var input = function () {}
58
            expect(Validator.state(input).violations).to.be.empty
0 ignored issues
show
introduced by
The result of the property access to expect(Validator.state(i...violations).to.be.empty is not used.
Loading history...
59
          })
60
        })
61
      })
62
    })
63
  })
64
})
65