find-and-count-all.test.js
1.36 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
'use strict';
const chai = require('chai'),
expect = chai.expect,
Support = require(__dirname + '/../support'),
current = Support.sequelize,
sinon = require('sinon'),
DataTypes = require(__dirname + '/../../../lib/data-types'),
Promise = require('bluebird').getNewLibraryCopy();
describe(Support.getTestDialectTeaser('Model'), () => {
describe('findAndCount', () => {
describe('should handle promise rejection', () => {
before(function() {
this.stub = sinon.stub();
Promise.onPossiblyUnhandledRejection(() => {
this.stub();
});
this.User = current.define('User', {
username: DataTypes.STRING,
age: DataTypes.INTEGER
});
this.findAll = sinon.stub(this.User, 'findAll').callsFake(() => {
return Promise.reject(new Error());
});
this.count = sinon.stub(this.User, 'count').callsFake(() => {
return Promise.reject(new Error());
});
});
after(function() {
this.findAll.resetBehavior();
this.count.resetBehavior();
});
it('with errors in count and findAll both', function() {
return this.User.findAndCount({})
.then(() => {
throw new Error();
})
.catch(() => {
expect(this.stub.callCount).to.eql(0);
});
});
});
});
});