Forked from arnaudbreton/async-process-jasmine.Spec.js
Last active
August 29, 2015 14:09
-
-
Save hengkiardo/185efd2c493e2ef27fe2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
}); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
foo.should.be.a('string'); | |
foo.should.equal('bar'); | |
foo.should.have.length(3); | |
tea.should.have.property('flavors').with.length(3); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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