Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Asynchronous Unit Tests With Mocha And WinJS Promises
describe("a test", function(){
var foo = false;
beforeEach(function(){
// simulate async call w/ setTimeout
setTimeout(function(){
foo = true;
}, 50);
});
it("should pass", function(){
expect(foo).equals(true);
});
});
describe("a test", function(){
var foo = false;
beforeEach(function(done){
setTimeout(function(){
foo = true;
// complete the async beforeEach
done();
}, 50);
});
it("should pass", function(){
expect(foo).equals(true);
});
});
describe("a test", function(){
var foo = false;
beforeEach(function(done){
var promise = new WinJS.Promise(function(complete){
complete(true);
});
promise.then(function(value){
// get the value from the completed promise
foo = value;
// complete the async beforeEach
done();
});
});
it("should pass", function(){
expect(foo).equals(true);
});
});
describe("a test", function(){
// ...
it("should pass", function(done){
// simulate async expecation
setTimeout(function(){
// complete the async expectation
done();
}, 50);
});
});
describe("a test", function(){
var foo = false;
var promise;
beforeEach(function(){
promise = new WinJS.Promise(function(complete){
// complete the promise with a value of false
// so that the expectation fails
complete(false);
});
});
it("should pass", function(done){
promise.then(function(value){
// expect the value to be true
// which should fail with a message
// saying it expected false to be true
expect(value).equals(true);
done();
});
});
});
promise
.then(thenCallback)
.done(thenCallback, errorCallback, completeCallback);
describe("a test", function(){
var foo = false;
var promise;
beforeEach(function(){
promise = new WinJS.Promise(function(complete){
// complete the promise with a value of false
// so that the expectation fails
complete(false);
});
});
it("should pass", function(done){
promise.then(function(value){
expect(value).equals(true);
done();
}).done(null, function(error){
// the expectation threw an error
// so forward that error to Mocha
done(error);
});
});
});
describe("a test", function(){
var foo = false;
var promise;
beforeEach(function(){
promise = new WinJS.Promise(function(complete){
// complete the promise with a value of false
// so that the expectation fails
complete(false);
});
});
it("should pass", function(done){
promise.then(function(value){
expect(value).equals(true);
done();
}).done(null, done); // <<-------
});
});
it("should pass", function(done){
promise.then(function(value){
expect(value).equals(true);
done();
}).done(done, done); // <<---- FAIL
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.