Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hengkiardo/185efd2c493e2ef27fe2 to your computer and use it in GitHub Desktop.
Save hengkiardo/185efd2c493e2ef27fe2 to your computer and use it in GitHub Desktop.
AsyncProcess = require('./async-process').AsyncProcess
describe('AsyncProcess', function() {
var asyncProcess;
beforeEach(function() {
asyncProcess = new AsyncProcess();
});
it('should process 42', function() {
var done = false;
var processed = null;
deferred = asyncProcess.process();
deferred.then(function(result) {
done = true;
processed = result;
});
waitsFor(function() {
return done;
}, "the async process to complete", 10000);
runs(function() {
expect(processed).toEqual(42);
});
});
});
AsyncProcess = require('./async-process').AsyncProcess;
Chai = require('chai');
Chai.should();
describe('AsyncProcess', function() {
var asyncProcess;
beforeEach(function() {
asyncProcess = new AsyncProcess();
});
it('should process 42', function(done) {
deferred = asyncProcess.process();
deferred.then(function(processed) {
processed.should.be.equal(42);
done();
});
});
});
Q = require('q');
var AsyncProcess = (function() {
function AsyncProcess() {}
AsyncProcess.prototype.process = function() {
var deferred;
deferred = Q.defer();
setTimeout((function() {
deferred.resolve(42);
}), 100);
return deferred.promise;
};
return AsyncProcess;
})();
exports.AsyncProcess = AsyncProcess;
foo.should.be.a('string');
foo.should.equal('bar');
foo.should.have.length(3);
tea.should.have.property('flavors').with.length(3);
// Function under test
function once(fn) {
var returnValue, called = false;
return function () {
if (!called) {
called = true;
returnValue = fn.apply(this, arguments);
}
return returnValue;
};
}
it("calls the original function", function () {
var spy = sinon.spy();
var proxy = once(spy);
proxy();
assert(spy.called);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment