不要怂,就是干,撸起袖子干!

Commit bf8246bc by Sascha Depold

added assertion for error messages

1 parent feca1473
......@@ -407,7 +407,7 @@ module.exports = (function() {
throw new Error(msg)
}
} else {
throw new Error('Include malformed. Expected attributes: daoFactory, as')
throw new Error('Include malformed. Expected attributes: daoFactory, as!')
}
} else {
throw new Error('Include unexpected. Element has to be either an instance of DAOFactory or an object.')
......
......@@ -2,6 +2,7 @@ const Sequelize = require(__dirname + "/../index")
, DataTypes = require(__dirname + "/../lib/data-types")
, config = require(__dirname + "/config/config")
, fs = require('fs')
, buster = require("buster")
var BusterHelpers = module.exports = {
Sequelize: Sequelize,
......@@ -95,5 +96,14 @@ var BusterHelpers = module.exports = {
} else {
throw new Error('Undefined expectation for "' + dialect + '"!')
}
},
assertException: function(block, msg) {
try {
block()
throw new Error('Passed function did not throw an error')
} catch(e) {
buster.assert.equals(e.message, msg)
}
}
}
......@@ -489,21 +489,21 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
})
it('throws an error about unexpected input if include contains a non-object', function() {
expect(function() {
Helpers.assertException(function() {
this.Worker.find({ include: [ 1 ] })
}.bind(this)).toThrow()
}.bind(this), 'Include unexpected. Element has to be either an instance of DAOFactory or an object.')
})
it('throws an error about missing attributes if include contains an object with daoFactory', function() {
expect(function() {
Helpers.assertException(function() {
this.Worker.find({ include: [ { daoFactory: this.Worker } ] })
}.bind(this)).toThrow()
}.bind(this), 'Include malformed. Expected attributes: daoFactory, as!')
})
it('throws an error if included DaoFactory is not associated', function() {
expect(function() {
Helpers.assertException(function() {
this.Worker.find({ include: [ this.Task ] })
}.bind(this)).toThrow()
}.bind(this), 'Task is not associated to Worker!')
})
it('returns the associated worker via task.worker', function(done) {
......@@ -537,9 +537,9 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
})
it('throws an error if included DaoFactory is not associated', function() {
expect(function() {
Helpers.assertException(function() {
this.Task.find({ include: [ this.Worker ] })
}.bind(this)).toThrow()
}.bind(this), 'Worker is not associated to Task!')
})
it('returns the associated task via worker.task', function(done) {
......@@ -573,9 +573,9 @@ describe(Helpers.getTestDialectTeaser("DAOFactory"), function() {
})
it('throws an error if included DaoFactory is not associated', function() {
expect(function() {
Helpers.assertException(function() {
this.Task.find({ include: [ this.Worker ] })
}.bind(this)).toThrow()
}.bind(this), 'Worker is not associated to Task!')
})
it('returns the associated tasks via worker.tasks', function(done) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!