不要怂,就是干,撸起袖子干!

Commit 81ce8ee3 by Andy Edwards Committed by GitHub

refactor(model): asyncify methods (#12122)

1 parent bccb447b
......@@ -651,10 +651,9 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
});
describe('restore', () => {
it('returns an error if the model is not paranoid', function() {
return this.User.create({ username: 'Peter', secretValue: '42' }).then(user => {
expect(() => {user.restore();}).to.throw(Error, 'Model is not paranoid');
});
it('returns an error if the model is not paranoid', async function() {
const user = await this.User.create({ username: 'Peter', secretValue: '42' });
await expect(user.restore()).to.be.rejectedWith(Error, 'Model is not paranoid');
});
it('restores a previously deleted model', function() {
......
......@@ -1555,11 +1555,8 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
describe('restore', () => {
it('synchronously throws an error if the model is not paranoid', async function() {
expect(() => {
this.User.restore({ where: { secretValue: '42' } });
throw new Error('Did not throw synchronously');
}).to.throw(Error, 'Model is not paranoid');
it('rejects with an error if the model is not paranoid', async function() {
await expect(this.User.restore({ where: { secretValue: '42' } })).to.be.rejectedWith(Error, 'Model is not paranoid');
});
it('restores a previously deleted model', async function() {
......
......@@ -18,14 +18,14 @@ describe(Support.getTestDialectTeaser('Model'), () => {
count: Sequelize.BIGINT
});
it('should reject if options are missing', () => {
return expect(() => Model.increment(['id', 'count']))
.to.throw('Missing where attribute in the options parameter');
it('should reject if options are missing', async () => {
await expect(Model.increment(['id', 'count']))
.to.be.rejectedWith('Missing where attribute in the options parameter');
});
it('should reject if options.where are missing', () => {
return expect(() => Model.increment(['id', 'count'], { by: 10 }))
.to.throw('Missing where attribute in the options parameter');
it('should reject if options.where are missing', async () => {
await expect(Model.increment(['id', 'count'], { by: 10 }))
.to.be.rejectedWith('Missing where attribute in the options parameter');
});
});
});
......
......@@ -9,15 +9,13 @@ const chai = require('chai'),
describe(Support.getTestDialectTeaser('Instance'), () => {
describe('save', () => {
it('should disallow saves if no primary key values is present', () => {
it('should disallow saves if no primary key values is present', async () => {
const Model = current.define('User', {
}),
instance = Model.build({}, { isNewRecord: false });
expect(() => {
instance.save();
}).to.throw();
await expect(instance.save()).to.be.rejected;
});
describe('options tests', () => {
......
......@@ -35,13 +35,10 @@ describe(Support.getTestDialectTeaser('Model'), () => {
this.stubDelete.restore();
});
it('can detect complex objects', () => {
it('can detect complex objects', async () => {
const Where = function() { this.secretValue = '1'; };
expect(() => {
User.destroy({ where: new Where() });
}).to.throw();
await expect(User.destroy({ where: new Where() })).to.be.rejected;
});
});
});
......@@ -65,9 +65,8 @@ describe(Support.getTestDialectTeaser('Model'), () => {
expect(this.warnOnInvalidOptionsStub.calledOnce).to.equal(true);
});
it('Throws an error when the attributes option is formatted incorrectly', () => {
const errorFunction = Model.findAll.bind(Model, { attributes: 'name' });
expect(errorFunction).to.throw(sequelizeErrors.QueryError);
it('Throws an error when the attributes option is formatted incorrectly', async () => {
await expect(Model.findAll({ attributes: 'name' })).to.be.rejectedWith(sequelizeErrors.QueryError);
});
});
......
......@@ -46,12 +46,10 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
});
it('can detect complexe objects', function() {
it('can detect complexe objects', async function() {
const Where = function() { this.secretValue = '1'; };
expect(() => {
this.User.update(this.updates, { where: new Where() });
}).to.throw();
await expect(this.User.update(this.updates, { where: new Where() })).to.be.rejected;
});
});
});
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!