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

Commit 466016ee by Rui Marinho

Replace sinon fake clock by promises

1 parent 45b84d31
...@@ -999,8 +999,6 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -999,8 +999,6 @@ describe(Support.getTestDialectTeaser('Model'), function() {
{ username: 'Paul', secretValue: '42' }, { username: 'Paul', secretValue: '42' },
{ username: 'Bob', secretValue: '43' }]; { username: 'Bob', secretValue: '43' }];
this.clock = sinon.useFakeTimers();
return this.User.bulkCreate(data).bind(this).then(function() { return this.User.bulkCreate(data).bind(this).then(function() {
return this.User.findAll({order: 'id'}); return this.User.findAll({order: 'id'});
}).then(function(users) { }).then(function(users) {
...@@ -1010,9 +1008,9 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -1010,9 +1008,9 @@ describe(Support.getTestDialectTeaser('Model'), function() {
expect(this.updatedAt).to.equalTime(users[2].updatedAt); // All users should have the same updatedAt expect(this.updatedAt).to.equalTime(users[2].updatedAt); // All users should have the same updatedAt
// Pass the time so we can actually see a change // Pass the time so we can actually see a change
this.clock.tick(1000); return this.sequelize.Promise.delay(1000).bind(this).then(function() {
return this.User.update({username: 'Bill'}, {where: {secretValue: '42'}});
return this.User.update({username: 'Bill'}, {where: {secretValue: '42'}}); });
}).then(function() { }).then(function() {
return this.User.findAll({order: 'id'}); return this.User.findAll({order: 'id'});
}).then(function(users) { }).then(function(users) {
...@@ -1022,8 +1020,6 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -1022,8 +1020,6 @@ describe(Support.getTestDialectTeaser('Model'), function() {
expect(users[0].updatedAt).to.be.afterTime(this.updatedAt); expect(users[0].updatedAt).to.be.afterTime(this.updatedAt);
expect(users[2].updatedAt).to.equalTime(this.updatedAt); expect(users[2].updatedAt).to.equalTime(this.updatedAt);
this.clock.restore();
}); });
}); });
......
...@@ -18,8 +18,6 @@ chai.config.includeStack = true; ...@@ -18,8 +18,6 @@ chai.config.includeStack = true;
describe(Support.getTestDialectTeaser('Model'), function() { describe(Support.getTestDialectTeaser('Model'), function() {
beforeEach(function() { beforeEach(function() {
this.clock = sinon.useFakeTimers();
this.User = this.sequelize.define('user', { this.User = this.sequelize.define('user', {
username: DataTypes.STRING, username: DataTypes.STRING,
foo: { foo: {
...@@ -35,10 +33,6 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -35,10 +33,6 @@ describe(Support.getTestDialectTeaser('Model'), function() {
return this.sequelize.sync({ force: true }); return this.sequelize.sync({ force: true });
}); });
afterEach(function() {
this.clock.restore();
});
if (current.dialect.supports.upserts) { if (current.dialect.supports.upserts) {
describe('upsert', function() { describe('upsert', function() {
it('works with upsert on id', function() { it('works with upsert on id', function() {
...@@ -49,8 +43,9 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -49,8 +43,9 @@ describe(Support.getTestDialectTeaser('Model'), function() {
expect(created).to.be.ok; expect(created).to.be.ok;
} }
this.clock.tick(2000); // Make sure to pass some time so updatedAt != createdAt return this.sequelize.Promise.delay(1000).bind(this).then(function() {
return this.User.upsert({ id: 42, username: 'doe' }); return this.User.upsert({ id: 42, username: 'doe' });
});
}).then(function(created) { }).then(function(created) {
if (dialect === 'sqlite') { if (dialect === 'sqlite') {
expect(created).not.to.be.defined; expect(created).not.to.be.defined;
...@@ -74,8 +69,9 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -74,8 +69,9 @@ describe(Support.getTestDialectTeaser('Model'), function() {
expect(created).to.be.ok; expect(created).to.be.ok;
} }
this.clock.tick(2000); // Make sure to pass some time so updatedAt != createdAt return this.sequelize.Promise.delay(1000).bind(this).then(function() {
return this.User.upsert({ foo: 'baz', bar: 19, username: 'doe' }); return this.User.upsert({ foo: 'baz', bar: 19, username: 'doe' });
});
}).then(function(created) { }).then(function(created) {
if (dialect === 'sqlite') { if (dialect === 'sqlite') {
expect(created).not.to.be.defined; expect(created).not.to.be.defined;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!