Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.