Skip to content

Instantly share code, notes, and snippets.

@kuldeepJadhav
Last active August 29, 2015 14:13
Show Gist options
  • Save kuldeepJadhav/a5f1806ecd0fe7683d43 to your computer and use it in GitHub Desktop.
Save kuldeepJadhav/a5f1806ecd0fe7683d43 to your computer and use it in GitHub Desktop.
Testing using jamine-node
var Q = require('q');
console.info("Q is "+Q);
exports.test = function() {
console.warn("Will call promise now");
return this.getQuestions().then(function() {
console.log("Test..");
return 'success';
});
};
exports.getQuestions = function() {
var deferred = Q.defer();
for(i=0; i<10; i++) {
if(i===3) {
deferred.resolve(i);
}
}
return deferred.promise;
// return {
// 'Question1': 'What is your name'
// }
}
var assert = require("assert");
var q = require('q');
var testFile = require('../routes/dataService');//include the dataService.js
var fs = require('fs');
describe('Tests', function(done) {
it('should run the test properly', function(done) {
console.log("Teststststst" + fs);
var flag = false;
var deferred;
spyOn(testFile, 'getQuestions').andCallFake(function() {
console.warn("Spy Called********************");
deferred = q.defer();
console.info("passing 1****");
deferred.resolve(1);
return deferred.promise;
});
spyOn(console, 'log');
runs(function() {
var p = testFile.test();
p.then(function() {
flag = true;
});
});
waitsFor(function() {
if (flag === true)
return true;
});
runs(function() {
console.info("Testststststsinggggggggg");
expect(console.log).toHaveBeenCalledWith("Test..");
console.info("Done*****************");
done();
});
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment