destroy.test.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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('method destroy', () => {
  10. const User = current.define('User', {
  11. name: DataTypes.STRING,
  12. secretValue: DataTypes.INTEGER,
  13. });
  14. before(function () {
  15. this.stubDelete = sinon.stub(current, 'queryRaw').resolves([]);
  16. });
  17. beforeEach(function () {
  18. this.deloptions = { where: { secretValue: '1' } };
  19. this.cloneOptions = { ...this.deloptions };
  20. this.stubDelete.resetHistory();
  21. });
  22. afterEach(function () {
  23. delete this.deloptions;
  24. delete this.cloneOptions;
  25. });
  26. after(function () {
  27. this.stubDelete.restore();
  28. });
  29. it('can detect complex objects', async () => {
  30. const Where = function () {
  31. this.secretValue = '1';
  32. };
  33. await expect(User.destroy({ where: new Where() })).to.be.rejected;
  34. });
  35. });
  36. });