Permalink
Browse files

Added a test for Promises only fulfilling once. Modified code to pass…

…. Added should and expresso to depDependencies.
  • Loading branch information...
1 parent 8ca9285 commit 5359935a6766bbae558295989f00f62947c92b4c @bnoguchi committed Jul 15, 2011
Showing with 23 additions and 2 deletions.
  1. +2 −1 lib/promise.js
  2. +3 −1 package.json
  3. +18 −0 test/promise.test.js
View
@@ -33,7 +33,8 @@ Promise.prototype = {
return this;
}
, fulfill: function () {
-// console.log(new Error().stack);
+ if (this.isFulfilled) return;
+ this.isFulfilled = true;
if (this._timeout) clearTimeout(this._timeout);
var callbacks = this._callbacks;
this.values = arguments;
View
@@ -23,7 +23,9 @@
"devDependencies": {
"express": ">=2.3.10",
"jade": ">=0.12.1",
- "tobi": ">=0.2.2"
+ "tobi": ">=0.2.2",
+ "expresso": ">=0.8.1",
+ "should": ">=0.2.1"
},
"engines": {
"node": ">=0.4.x"
View
@@ -0,0 +1,18 @@
+var should = require('should')
+ , Promise = require('../lib/promise');
+
+module.exports = {
+ 'fulfill called >1 times should only have an effect once': function (done) {
+ var p = new Promise()
+ , test = null;
+ p.callback( function (val) {
+ test = val;
+ });
+ p.fulfill(1);
+ p.fulfill(2);
+ setTimeout( function () {
+ test.should.equal(1);
+ done();
+ }, 1000);
+ }
+};

0 comments on commit 5359935

Please sign in to comment.