Debian Codegraph @

test/NamedNode-test.js

raw
1 import { NamedNode, Term } from '../src/';
2
3 describe('NamedNode', () => {
4 describe('The NamedNode module', () => {
5 it('should be a function', () => {
6 NamedNode.should.be.a('function');
7 });
8
9 it('should be a NamedNode constructor', () => {
10 new NamedNode().should.be.an.instanceof(NamedNode);
11 });
12
13 it('should be a Term constructor', () => {
14 new NamedNode().should.be.an.instanceof(Term);
15 });
16 });
17
18 describe('A NamedNode instance created from an IRI', () => {
19 let namedNode;
20 before(() => { namedNode = new NamedNode('http://example.org/foo#bar'); });
21
22 it('should be a NamedNode', () => {
23 namedNode.should.be.an.instanceof(NamedNode);
24 });
25
26 it('should be a Term', () => {
27 namedNode.should.be.an.instanceof(Term);
28 });
29
30 it('should have term type "NamedNode"', () => {
31 namedNode.termType.should.equal('NamedNode');
32 });
33
34 it('should have the IRI as value', () => {
35 namedNode.should.have.property('value', 'http://example.org/foo#bar');
36 });
37
38 it('should have the IRI as id', () => {
39 namedNode.should.have.property('id', 'http://example.org/foo#bar');
40 });
41
42 it('should equal a NamedNode instance with the same IRI', () => {
43 namedNode.equals(new NamedNode('http://example.org/foo#bar')).should.be.true;
44 });
45
46 it('should equal an object with the same term type and value', () => {
47 namedNode.equals({
48 termType: 'NamedNode',
49 value: 'http://example.org/foo#bar',
50 }).should.be.true;
51 });
52
53 it('should not equal a falsy object', () => {
54 namedNode.equals(null).should.be.false;
55 });
56
57 it('should not equal a NamedNode instance with another IRI', () => {
58 namedNode.equals(new NamedNode('http://example.org/other')).should.be.false;
59 });
60
61 it('should not equal an object with the same term type but a different value', () => {
62 namedNode.equals({
63 termType: 'NamedNode',
64 value: 'http://example.org/other',
65 }).should.be.false;
66 });
67
68 it('should not equal an object with a different term type but the same value', () => {
69 namedNode.equals({
70 termType: 'BlankNode',
71 value: 'http://example.org/foo#bar',
72 }).should.be.false;
73 });
74
75 it('should provide a JSON representation', () => {
76 namedNode.toJSON().should.deep.equal({
77 termType: 'NamedNode',
78 value: 'http://example.org/foo#bar',
79 });
80 });
81 });
82 });