find-and-count-all.test.js
1.13 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
'use strict';
const chai = require('chai'),
expect = chai.expect,
Support = require('../support'),
current = Support.sequelize,
sinon = require('sinon'),
DataTypes = require('../../../lib/data-types');
describe(Support.getTestDialectTeaser('Model'), () => {
describe('findAndCountAll', () => {
describe('should handle promise rejection', () => {
before(function() {
this.stub = sinon.stub();
process.on('unhandledRejection', this.stub);
this.User = current.define('User', {
username: DataTypes.STRING,
age: DataTypes.INTEGER
});
this.findAll = sinon.stub(this.User, 'findAll').rejects(new Error());
this.count = sinon.stub(this.User, 'count').rejects(new Error());
});
after(function() {
this.findAll.resetBehavior();
this.count.resetBehavior();
});
it('with errors in count and findAll both', async function() {
try {
await this.User.findAndCountAll({});
throw new Error();
} catch (err) {
expect(this.stub.callCount).to.eql(0);
}
});
});
});
});