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

Commit 81ce8ee3 by Andy Edwards Committed by GitHub

refactor(model): asyncify methods (#12122)

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