Debian Codegraph @

test/BlankNode-test.js

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