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

Commit eacbac80 by joao.bortolozzo

Test assert against stub

1 parent 14da0d26
Showing with 27 additions and 14 deletions
...@@ -27,30 +27,43 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -27,30 +27,43 @@ describe(Support.getTestDialectTeaser('Model'), function() {
name: 'John' name: 'John'
}); });
this.stub = stub(this.User.sequelize, 'transaction'); this.transactionStub = stub(this.User.sequelize, 'transaction');
this.stub.returns(new Promise(function () {})); this.transactionStub.returns(new Promise(function () {}));
this.clsStub = stub(current.constructor.cls, 'get');
this.clsStub.returns({ id: 123 });
}); });
afterEach(function () { afterEach(function () {
this.stub.restore(); this.transactionStub.restore();
this.clsStub.restore();
}); });
it('should use transaction from cls if available', function () { it('should use transaction from cls if available', function () {
var self = this;
current.constructor.cls.run(function () { var options = {
current.constructor.cls.set('transaction', { id: 123 }); where : {
name : 'John'
}
};
var options = { this.User.findOrCreate(options);
where : {
name : 'John'
}
};
self.User.findOrCreate(options); expect(this.clsStub.calledOnce).to.equal(true, 'expected to ask for transaction');
});
expect(options.transaction).to.have.property('id', 123); it('should not use transaction from cls if provided as argument', function () {
});
var options = {
where : {
name : 'John'
},
transaction : { id : 123 }
};
this.User.findOrCreate(options);
expect(this.clsStub.called).to.equal(false);
}); });
}); });
}); });
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!