Skip to content

Commit 42d943b

Browse files
committed
test(Model): reworked model.js test
* cleaned up test code to be as asynchronous as possible * used chai/chai-as-expected to make tests more readable * introduced test-fixture to properly track/clean/drop tables throughout all test runs * made sure to wait for all table creation before operating on those tables
1 parent be833eb commit 42d943b

5 files changed

Lines changed: 970 additions & 13 deletions

File tree

lib/model.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ Model.prototype.hasAndBelongsToMany = function(joinedModel, fieldDoc, leftKey, r
549549

550550
var linkModel;
551551
if (thinky.models[link] === undefined) {
552-
linkModel = thinky.createModel(link, {}); // Create a model, claim the namespace and create the table
552+
linkModel = thinky.createModel(link, {}, options); // Create a model, claim the namespace and create the table
553553
}
554554
else {
555555
linkModel = thinky.models[link];

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"test": "test"
88
},
99
"scripts": {
10-
"test": "mocha --check-leaks -t 20000"
10+
"test": "mocha --check-leaks -t 30000"
1111
},
1212
"repository": {
1313
"type": "git",
@@ -29,6 +29,8 @@
2929
"validator": "~ 3.22.1"
3030
},
3131
"devDependencies": {
32-
"mocha": "~1.21.5"
32+
"mocha": "^2.2.5",
33+
"chai": "^3.2.0",
34+
"chai-as-promised": "^5.1.0"
3335
}
3436
}

test/model.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -356,16 +356,11 @@ describe("Joins", function() {
356356

357357

358358
model.hasAndBelongsToMany(otherModel, "otherDoc", "id", "otherId", {init: false});
359-
try{
360-
model.hasAndBelongsToMany(anotherModel, "otherDoc", "id", "otherId");
361-
}
362-
catch(err) {
363-
assert.equal(err.message, "The field `otherDoc` is already used by another relation.")
364-
// Wait for the link table to be ready since we wont' drop/recreate the table
365-
thinky.models[model._getModel()._joins["otherDoc"].link].once('ready', function() {
366-
// TODO Remove when tableWait is implemented on the server
367-
done();
368-
})
359+
try {
360+
model.hasAndBelongsToMany(anotherModel, "otherDoc", "id", "otherId", {init: false});
361+
} catch(err) {
362+
assert.equal(err.message, "The field `otherDoc` is already used by another relation.");
363+
done();
369364
}
370365
});
371366
it('hasOne should throw if the first argument is not a model', function(done) {

0 commit comments

Comments
 (0)