find-and-count-all.test.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. 'use strict';
  2. const chai = require('chai');
  3. const expect = chai.expect;
  4. const Support = require('../../support');
  5. const current = Support.sequelize;
  6. const sinon = require('sinon');
  7. const { DataTypes } = require('@sequelize/core');
  8. describe(Support.getTestDialectTeaser('Model'), () => {
  9. describe('findAndCountAll', () => {
  10. describe('should handle promise rejection', () => {
  11. before(function () {
  12. this.stub = sinon.stub();
  13. process.on('unhandledRejection', this.stub);
  14. this.User = current.define('User', {
  15. username: DataTypes.STRING,
  16. age: DataTypes.INTEGER,
  17. });
  18. this.findAll = sinon.stub(this.User, 'findAll').rejects(new Error());
  19. this.count = sinon.stub(this.User, 'count').rejects(new Error());
  20. });
  21. after(function () {
  22. this.findAll.resetBehavior();
  23. this.count.resetBehavior();
  24. });
  25. it('with errors in count and findAll both', async function () {
  26. try {
  27. await this.User.findAndCountAll({});
  28. throw new Error();
  29. } catch {
  30. expect(this.stub.callCount).to.eql(0);
  31. }
  32. });
  33. });
  34. });
  35. });