error.test.js
2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* jshint camelcase: false */
var chai = require('chai')
, expect = chai.expect
, Support = require(__dirname + '/support')
, Sequelize = Support.Sequelize;
chai.config.includeStack = true;
describe(Support.getTestDialectTeaser("Sequelize Errors"), function () {
describe('API Surface', function() {
it('Should have the Error constructors exposed', function() {
expect(Sequelize).to.have.property('Error');
expect(Sequelize).to.have.property('ValidationError');
var sequelize = new Sequelize();
expect(sequelize).to.have.property('Error');
expect(sequelize).to.have.property('ValidationError');
});
it('Sequelize Errors instances should be instances of Error', function() {
var error = new Sequelize.Error();
var validationError = new Sequelize.ValidationError();
var sequelize = new Sequelize();
var instError = new sequelize.Error();
var instValidationError = new sequelize.ValidationError();
expect(error).to.be.instanceOf(Sequelize.Error);
expect(error).to.be.instanceOf(Error);
expect(error).to.have.property('name', 'SequelizeBaseError');
expect(validationError).to.be.instanceOf(Sequelize.ValidationError);
expect(validationError).to.be.instanceOf(Error);
expect(validationError).to.have.property('name', 'SequelizeValidationError');
expect(instError).to.be.instanceOf(Sequelize.Error);
expect(instError).to.be.instanceOf(Error);
expect(instValidationError).to.be.instanceOf(Sequelize.ValidationError);
expect(instValidationError).to.be.instanceOf(Error);
});
it('SequelizeValidationError should find errors by path', function() {
var errorItems = [
new Sequelize.ValidationErrorItem('invalid', 'type', 'first_name', null),
new Sequelize.ValidationErrorItem('invalid', 'type', 'last_name', null)
];
var validationError = new Sequelize.ValidationError('Validation error', errorItems);
expect(validationError).to.have.property('get');
expect(validationError.get).to.be.a('function');
var matches = validationError.get('first_name');
expect(matches).to.be.instanceOf(Array);
expect(matches).to.have.lengthOf(1);
expect(matches[0]).to.have.property('message', 'invalid')
});
})
});