index.js
1.6 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
let expect = require('chai').expect;
let api = require('../src/index.js');
let path = require('path');
describe('index.js', function() {
it('should not accept number arguments', function() {
expect(function() { api(5); }).to.throw('Bookshelf API requires a config object.');
});
it('should not accept string arguments', function() {
expect(function() { api('test'); }).to.throw('Bookshelf API requires a config object.');
});
it('should not accept boolean arguments', function() {
expect(function() { api(false); }).to.throw('Bookshelf API requires a config object.');
});
it('should not accept object arguments without a path property', function() {
expect(function() { api({}); }).to.throw('Bookshelf API configuration object requires a path property specifying where your models directory is located.');
expect(function() { api({foo: 'test'}); }).to.throw('Bookshelf API configuration object requires a path property specifying where your models directory is located.');
});
it('should throw an error if the path is invalid', function() {
expect(function() { api({path: 'foo'}); }).to.throw('Could not find the model path foo.');
});
it('should work if the path is valid and absolute', function() {
expect(function(){ api({
path: path.join(__dirname, 'fixtures/models')
}); }).to.not.throw();
expect(api({
path: path.join(__dirname, 'fixtures/models')
})).to.be.a.function;
});
it('should work if the path is valid and relative', function() {
expect(function(){ api({
path: 'fixtures/models'
}); }).to.not.throw();
expect(api({
path: 'fixtures/models'
})).to.be.a.function;
});
});