Skip to content

Commit fde1251

Browse files
committed
Merge pull request #7 from elf-pavlik/master
optimised test assertions for readibility
2 parents 5780e14 + a4f25d4 commit fde1251

3 files changed

Lines changed: 24 additions & 20 deletions

File tree

test/del_spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe("jsonld.del", function() {
2626
db.jsonld.del(manu, function() {
2727
db.get({}, function(err, triples) {
2828
// getting the full db
29-
expect(triples).to.have.property("length", 0);
29+
expect(triples).to.be.empty;
3030
done();
3131
});
3232
});
@@ -38,7 +38,7 @@ describe("jsonld.del", function() {
3838
db.jsonld.del(tesla, function() {
3939
db.get({}, function(err, triples) {
4040
// getting the full db
41-
expect(triples).to.have.property("length", 0);
41+
expect(triples).to.be.empty;
4242
done();
4343
});
4444
});
@@ -50,7 +50,7 @@ describe("jsonld.del", function() {
5050
db.jsonld.del(manu["@id"], function() {
5151
db.get({}, function(err, triples) {
5252
// getting the full db
53-
expect(triples).to.have.property("length", 0);
53+
expect(triples).to.be.empty;
5454
done();
5555
});
5656
});
@@ -63,7 +63,7 @@ describe("jsonld.del", function() {
6363
db.jsonld.del(tesla, function() {
6464
db.get({}, function(err, triples) {
6565
// getting the full db
66-
expect(triples).to.have.property("length", 2);
66+
expect(triples).to.have.length(2);
6767
done();
6868
});
6969
});

test/get_spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe("jsonld.get", function() {
3030

3131
it("should load it", function(done) {
3232
db.jsonld.get(manu["@id"], { "@context": manu["@context"] }, function(err, obj) {
33-
expect(obj).to.be.eql(manu);
33+
expect(obj).to.eql(manu);
3434
done();
3535
});
3636
});

test/put_spec.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe("jsonld.put", function() {
2727
, predicate: "http://xmlns.com/foaf/0.1/name"
2828
, object: "Manu Sporny"
2929
}, function(err, triples) {
30-
expect(triples).to.have.property("length", 1);
30+
expect(triples).to.have.length(1);
3131
done();
3232
});
3333
});
@@ -38,7 +38,7 @@ describe("jsonld.put", function() {
3838
db.get({
3939
subject: "http://manu.sporny.org#person"
4040
}, function(err, triples) {
41-
expect(triples).to.have.property("length", 2);
41+
expect(triples).to.have.length(2);
4242
done();
4343
});
4444
});
@@ -49,7 +49,7 @@ describe("jsonld.put", function() {
4949
db.get({
5050
subject: "http://manu.sporny.org#person"
5151
}, function(err, triples) {
52-
expect(triples).to.have.property("length", 2);
52+
expect(triples).to.have.length(2);
5353
done();
5454
});
5555
});
@@ -63,32 +63,36 @@ describe("jsonld.put", function() {
6363
, predicate: "http://xmlns.com/foaf/0.1/name"
6464
, object: "Manu Sporny"
6565
}, function(err, triples) {
66-
expect(triples).to.have.property("length", 1);
66+
expect(triples).to.have.length(1);
6767
done();
6868
});
6969
});
7070
});
7171

7272
it("should generate an @id for unknown objects", function(done) {
7373
delete manu["@id"];
74+
var baseString = "http://levelgraph.org/tests/";
75+
var baseRegEx = /^http:\/\/levelgraph.org\/tests\//;
7476

75-
db.jsonld.put(manu, { base: "http://levelgraph.org/tests/" }, function() {
77+
db.jsonld.put(manu, { base: baseString }, function() {
7678
db.join({
7779
subject: db.v("subject")
7880
, predicate: "http://xmlns.com/foaf/0.1/name"
7981
, object: "Manu Sporny"
8082
}, function(err, contexts) {
81-
expect(contexts[0].subject.indexOf("http://levelgraph.org/tests/")).to.equal(0);
83+
expect(contexts[0].subject).to.match(baseRegEx);
8284
done();
8385
});
8486
});
8587
});
8688

8789
it("should pass the generated @id to callback", function(done) {
8890
delete manu["@id"];
91+
var baseString = "http://levelgraph.org/tests/";
92+
var baseRegEx = /^http:\/\/levelgraph.org\/tests\//;
8993

90-
db.jsonld.put(manu, { base: "http://levelgraph.org/tests/" }, function(err, obj) {
91-
expect(obj["@id"].indexOf("http://levelgraph.org/tests/")).to.equal(0);
94+
db.jsonld.put(manu, { base: baseString }, function(err, obj) {
95+
expect(obj["@id"]).to.match(baseRegEx);
9296
done();
9397
});
9498
});
@@ -100,7 +104,7 @@ describe("jsonld.put", function() {
100104
, predicate: "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
101105
, object: "http://purl.org/goodrelations/v1#Offering"
102106
}, function(err, triples) {
103-
expect(triples).to.have.property("length", 1);
107+
expect(triples).to.have.length(1);
104108
done();
105109
});
106110
});
@@ -115,7 +119,7 @@ describe("jsonld.put", function() {
115119
, predicate: "http://xmlns.com/foaf/0.1/homepage"
116120
, object: "http://another/website"
117121
}, function(err, triples) {
118-
expect(triples).to.have.property("length", 1);
122+
expect(triples).to.have.length(1);
119123
done();
120124
});
121125
});
@@ -133,7 +137,7 @@ describe("jsonld.put", function() {
133137
, predicate: "http://xmlns.com/foaf/0.1/age"
134138
, object: 42
135139
}, function(err, triples) {
136-
expect(triples).to.have.property("length", 1);
140+
expect(triples).to.have.length(1);
137141
done();
138142
});
139143
});
@@ -149,7 +153,7 @@ describe("jsonld.put", function() {
149153
subject: "http://manu.sporny.org#person"
150154
, predicate: "http://xmlns.com/foaf/0.1/homepage"
151155
}, function(err, triples) {
152-
expect(triples).to.have.property("length", 0);
156+
expect(triples).to.be.empty;
153157
done();
154158
});
155159
});
@@ -165,7 +169,7 @@ describe("jsonld.put", function() {
165169
subject: "http://example.org/cars/for-sale#tesla"
166170
, predicate: "http://purl.org/goodrelations/v1#"
167171
}, function(err, triples) {
168-
expect(triples).to.have.property("length", 0);
172+
expect(triples).to.be.empty;
169173
done();
170174
});
171175
});
@@ -194,7 +198,7 @@ describe("jsonld.put with default base", function() {
194198
, predicate: "http://xmlns.com/foaf/0.1/name"
195199
, object: "Manu Sporny"
196200
}, function(err, triples) {
197-
expect(triples).to.have.property("length", 1);
201+
expect(triples).to.have.length(1);
198202
done();
199203
});
200204
});
@@ -237,7 +241,7 @@ describe("jsonld.put with default base", function() {
237241

238242
db.jsonld.put(nested, function() {
239243
db.get({}, function(err, triples) {
240-
expect(triples).to.have.property("length", 5);
244+
expect(triples).to.have.length(5);
241245
done();
242246
});
243247
});

0 commit comments

Comments
 (0)