Completed
Pull Request — master (#13)
by Justin
07:02
created

test/ResourceReference.js   A

Complexity

Total Complexity 6
Complexity/F 1

Size

Lines of Code 39
Function Count 6

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 0
c 2
b 0
f 0
nc 1
dl 0
loc 39
rs 10
wmc 6
mnd 0
bc 6
fnc 6
bpm 1
cpm 1
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
B ResourceReference.js ➔ describe(ꞌResourceReferenceꞌ) 0 36 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
});