test/core/ResourceReference.js   A
last analyzed

Complexity

Total Complexity 7
Complexity/F 1

Size

Lines of Code 45
Function Count 7

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 45
rs 10
wmc 7
mnd 0
bc 7
fnc 7
bpm 1
cpm 1
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
B ResourceReference.js ➔ describe(ꞌResourceReferenceꞌ) 0 42 1
1
var assert = require('chai').assert,
2
    GedcomX = require('../../');
3
4
describe('ResourceReference', function(){
5
  
6
  it('Create plain', function(){
7
    var newRR = new GedcomX.ResourceReference(),
8
        rr = GedcomX.ResourceReference();
9
    assert.instanceOf(newRR, GedcomX.ResourceReference, 'An instance of ResourceReference is not returned when calling the constructor with new.');
10
    assert.instanceOf(rr, GedcomX.ResourceReference, 'An instance of ResourceReference is not returned when calling the constructor without new.');
11
  });
12
  
13
  it('Create with JSON', function(){
14
    var rr = GedcomX.ResourceReference({ resource: 'http://example.com' });
15
    assert.equal(rr.getResource(), 'http://example.com', 'Resource not saved properly when created with JSON');
16
  });
17
  
18
  it('Change resource', function(){
19
    var rr = GedcomX.ResourceReference({ resource: 'http://example.com' });
20
    rr.setResource('http://newuri.com');
21
    assert.equal(rr.getResource(), 'http://newuri.com', 'Resource not saved properly when changed with setResource()');
22
  });
23
  
24
  it('toJSON()', function(){
25
    var rr = GedcomX.ResourceReference({ resource: 'http://example.com' });
26
    rr.setResource('http://newuri.com');
27
    assert.deepEqual(rr.toJSON(), { resource: 'http://newuri.com' }, 'JSON export is incorrect');
28
    
29
    rr = GedcomX.ResourceReference();
30
    assert.deepEqual(rr.toJSON(), {});
31
  });
32
  
33
  it('constructor does not copy instances', function(){
34
    var obj1 = GedcomX.ResourceReference();
35
    var obj2 = GedcomX.ResourceReference(obj1);
36
    assert.strictEqual(obj1, obj2);
37
  });
38
  
39
  it('matches()', function(){
40
    var reference = GedcomX.ResourceReference({ resource: '#resource' });
41
    assert(reference.matches('resource'));
42
    assert(!reference.matches());
43
  });
44
  
45
});