Skip to content

Commit

Permalink
chore: migrate to jest
Browse files Browse the repository at this point in the history
  • Loading branch information
jeswr committed Oct 13, 2023
1 parent 022c958 commit ae55159
Show file tree
Hide file tree
Showing 19 changed files with 16,929 additions and 11,143 deletions.
8 changes: 0 additions & 8 deletions .mocharc.json

This file was deleted.

20,506 changes: 12,443 additions & 8,063 deletions package-lock.json

Large diffs are not rendered by default.

13 changes: 6 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,10 @@
"@rdfjs/data-model": "^1",
"arrayify-stream": "^1.0.0",
"browserify": "^17.0.0",
"chai": "^4.0.2",
"chai-things": "^0.2.0",
"colors": "^1.1.2",
"docco": "^0.8.0",
"eslint": "^5.14.1",
"mocha": "^8.0.0",
"nyc": "^14.1.1",
"jest": "^29.7.0",
"pre-commit": "^1.2.2",
"rdf-isomorphic": "^1.3.1",
"rdf-test-suite": "^1.19.2",
Expand All @@ -52,8 +49,7 @@
"build": "npm run build:node && npm run build:browser",
"build:node": "babel src -d lib",
"build:browser": "rm -rf browser && mkdir browser && browserify -s N3 lib/index.js | uglifyjs > browser/n3.min.js",
"test": "nyc npm run mocha",
"mocha": "mocha",
"test": "jest",
"lint": "eslint src perf test spec",
"prepare": "npm run build",
"spec": "npm run spec-turtle && npm run spec-ntriples && npm run spec-nquads && npm run spec-trig",
Expand All @@ -79,5 +75,8 @@
"pre-commit": [
"lint",
"test"
]
],
"jest": {
"testMatch": ["**/test/*-test.js"]
}
}
1 change: 1 addition & 0 deletions test/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
before: true,
after: true,
beforeEach: true,
beforeAll: true,
afterEach: true,
expect: true,
},
Expand Down
62 changes: 34 additions & 28 deletions test/BlankNode-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,77 +3,83 @@ import { BlankNode, Term } from '../src/';
describe('BlankNode', () => {
describe('The BlankNode module', () => {
it('should be a function', () => {
BlankNode.should.be.a('function');
expect(BlankNode).toBeInstanceOf(Function);
});

it('should be a BlankNode constructor', () => {
new BlankNode().should.be.an.instanceof(BlankNode);
expect(new BlankNode()).toBeInstanceOf(BlankNode);
});

it('should be a Term constructor', () => {
new BlankNode().should.be.an.instanceof(Term);
expect(new BlankNode()).toBeInstanceOf(Term);
});
});

describe('A BlankNode instance created from a name', () => {
let blankNode;
before(() => { blankNode = new BlankNode('b1'); });
beforeAll(() => { blankNode = new BlankNode('b1'); });

it('should be a BlankNode', () => {
blankNode.should.be.an.instanceof(BlankNode);
expect(blankNode).toBeInstanceOf(BlankNode);
});

it('should be a Term', () => {
blankNode.should.be.an.instanceof(Term);
expect(blankNode).toBeInstanceOf(Term);
});

it('should have term type "BlankNode"', () => {
blankNode.termType.should.equal('BlankNode');
expect(blankNode.termType).toBe('BlankNode');
});

it('should have the name as value', () => {
blankNode.should.have.property('value', 'b1');
expect(blankNode).toHaveProperty('value', 'b1');
});

it('should have "_:name" as id', () => {
blankNode.should.have.property('id', '_:b1');
expect(blankNode).toHaveProperty('id', '_:b1');
});

it('should equal a BlankNode instance with the same name', () => {
blankNode.equals(new BlankNode('b1')).should.be.true;
expect(blankNode.equals(new BlankNode('b1'))).toBe(true);
});

it('should equal an object with the same term type and value', () => {
blankNode.equals({
expect(blankNode.equals({
termType: 'BlankNode',
value: 'b1',
}).should.be.true;
})).toBe(true);
});

it('should not equal a falsy object', () => {
blankNode.equals(null).should.be.false;
expect(blankNode.equals(null)).toBe(false);
});

it('should not equal a BlankNode instance with another name', () => {
blankNode.equals(new BlankNode('b2')).should.be.false;
expect(blankNode.equals(new BlankNode('b2'))).toBe(false);
});

it('should not equal an object with the same term type but a different value', () => {
blankNode.equals({
termType: 'BlankNode',
value: 'b2',
}).should.be.false;
});

it('should not equal an object with a different term type but the same value', () => {
blankNode.equals({
termType: 'NamedNode',
value: 'b1',
}).should.be.false;
});
it(
'should not equal an object with the same term type but a different value',
() => {
expect(blankNode.equals({
termType: 'BlankNode',
value: 'b2',
})).toBe(false);
}
);

it(
'should not equal an object with a different term type but the same value',
() => {
expect(blankNode.equals({
termType: 'NamedNode',
value: 'b1',
})).toBe(false);
}
);

it('should provide a JSON representation', () => {
blankNode.toJSON().should.deep.equal({
expect(blankNode.toJSON()).toEqual({
termType: 'BlankNode',
value: 'b1',
});
Expand Down
32 changes: 16 additions & 16 deletions test/DefaultGraph-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,64 +3,64 @@ import { DefaultGraph, Term } from '../src/';
describe('DefaultGraph', () => {
describe('The DefaultGraph module', () => {
it('should be a function', () => {
DefaultGraph.should.be.a('function');
expect(DefaultGraph).toBeInstanceOf(Function);
});

it('should be a DefaultGraph constructor', () => {
new DefaultGraph().should.be.an.instanceof(DefaultGraph);
expect(new DefaultGraph()).toBeInstanceOf(DefaultGraph);
});

it('should be a Term constructor', () => {
new DefaultGraph().should.be.an.instanceof(Term);
expect(new DefaultGraph()).toBeInstanceOf(Term);
});
});

describe('A DefaultGraph instance', () => {
let defaultGraph;
before(() => { defaultGraph = new DefaultGraph(); });
beforeAll(() => { defaultGraph = new DefaultGraph(); });

it('should be a DefaultGraph', () => {
defaultGraph.should.be.an.instanceof(DefaultGraph);
expect(defaultGraph).toBeInstanceOf(DefaultGraph);
});

it('should be a Term', () => {
defaultGraph.should.be.an.instanceof(Term);
expect(defaultGraph).toBeInstanceOf(Term);
});

it('should have term type "DefaultGraph"', () => {
defaultGraph.termType.should.equal('DefaultGraph');
expect(defaultGraph.termType).toBe('DefaultGraph');
});

it('should have the empty string as value', () => {
defaultGraph.should.have.property('value', '');
expect(defaultGraph).toHaveProperty('value', '');
});

it('should have the empty string as id', () => {
defaultGraph.should.have.property('id', '');
expect(defaultGraph).toHaveProperty('id', '');
});

it('should equal another DefaultGraph instance', () => {
defaultGraph.equals(new DefaultGraph()).should.be.true;
expect(defaultGraph.equals(new DefaultGraph())).toBe(true);
});

it('should equal an object with the same term type', () => {
defaultGraph.equals({
expect(defaultGraph.equals({
termType: 'DefaultGraph',
}).should.be.true;
})).toBe(true);
});

it('should not equal a falsy object', () => {
defaultGraph.equals(null).should.be.false;
expect(defaultGraph.equals(null)).toBe(false);
});

it('should not equal an object with a different term type', () => {
defaultGraph.equals({
expect(defaultGraph.equals({
termType: 'Literal',
}).should.be.false;
})).toBe(false);
});

it('should provide a JSON representation', () => {
defaultGraph.toJSON().should.deep.equal({
expect(defaultGraph.toJSON()).toEqual({
termType: 'DefaultGraph',
value: '',
});
Expand Down
Loading

0 comments on commit ae55159

Please sign in to comment.