drop-table.test.ts 956 B

12345678910111213141516171819202122232425262728293031
  1. import { expect } from 'chai';
  2. import sinon from 'sinon';
  3. import { expectsql, getTestDialect, sequelize } from '../../support';
  4. const dialectName = getTestDialect();
  5. describe('QueryInterface#dropTable', () => {
  6. afterEach(() => {
  7. sinon.restore();
  8. });
  9. it('produces a DROP TABLE query with cascade', async () => {
  10. if (sequelize.dialect.supports.dropTable.cascade) {
  11. const stub = sinon.stub(sequelize, 'queryRaw');
  12. await sequelize.queryInterface.dropTable('myTable', { cascade: true });
  13. expect(stub.callCount).to.eq(1);
  14. const firstCall = stub.getCall(0);
  15. expectsql(firstCall.args[0], {
  16. default: 'DROP TABLE IF EXISTS [myTable] CASCADE',
  17. });
  18. } else {
  19. await expect(
  20. sequelize.queryInterface.dropTable('myTable', { cascade: true }),
  21. ).to.be.rejectedWith(
  22. `The following options are not supported by dropTableQuery in ${dialectName}: cascade`,
  23. );
  24. }
  25. });
  26. });